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
hgis 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
alogand simply train your fingers to typehg aloginstead ofhg log. Placing this in~/.hgrc(or equivalent) will do it:Why is this a better solution? Not only does an alias for
logblock 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 login an another account or context that's not controlled by your.hgrc. (Typinghg alogin the same circumstances will only incur an "unknown command" error).