Instead, you can create a function in .bash_profile
. It will allow you to use variables:
glog ()
{
git log --all --pretty=format:'%h %cd %s (%an)' --since="$1"
}
And call it like usual:
glog "7 days ago"
quick follow-up: how would I change the function to allow the possibility of also appending the --author="so-and-so" flag? as in, I could type glog "7 days ago" or blog "7 days ago" --author="bob"
I would do as like follows:
glog ()
{
if [ -z "$2" ]; then
git log --all --pretty=format:'%h %cd %s (%an)' --since="$1"
else
git log --all --pretty=format:'%h %cd %s (%an)' --since="$1" --author="$2"
fi
}
So you can call it with
glog "7 days ago"
glog "7 days ago" "bob"
Note that the if [ -z "$2" ]; then
condition is checking if the second parameter is empty. If so, just executes the code without author
. Otherwise, it uses it.