Is it possible to change the default behaviour of hg log
to show only the current ancestors?
Ie this:
hg log --rev "reverse(ancestors(.))"
The thing is, I always want hg log
to do that.
I know that I could do something like this in my .bashrc
but I was wondering if there was a mercurial way to do this.
hg () {
if [[ $2 -eq "log" ]]
then
# TODO: Append other arguments to this...
hg log --rev "reverse(ancestors(.))"
else
# Run the command
fi
}
The alias function of
hg
is the right tool for this. While you can create aliases that modify the default behavior of built-in commands,hg config
(section"alias"
) has the following to say:The recommended practice is to create an alias
alog
and simply train your fingers to typehg alog
instead ofhg log
. Placing this in~/.hgrc
(or equivalent) will do it:Why is this a better solution? Not only does an alias for
log
block you from accessing the original behavior (requiring another alias that claws back the original meaning); more importantly, once you come to expect the non-standard behavior, sooner or later you'll get bit when you typehg log
in an another account or context that's not controlled by your.hgrc
. (Typinghg alog
in the same circumstances will only incur an "unknown command" error).