Prettier Mercurial output

August 20th, 2012

I don’t use git on a daily basis, but I’m a fan of how its output is both colorful and run through a pager (like less) if necessary. As it turns out, Mercurial (which I do use daily) ships with all the functionality you need to replicate this behavior, it’s just not enabled by default. You need to enable the color and pager extensions (which ship with Mercurial), so just a few lines in your ~/.hgrc will get you there:

[extensions]
color =
pager =
[pager]
pager = LESS=FRSXQ less
quiet = True

The pager configuration simply makes less handle the colored output properly, and also behave like cat if the output fits on the screen.

I frequently find myself using hg export to view the contents of patches in my mq, so I also added an alias that I could use instead to get nice colored and pagered diffs:

[alias]
show = log --patch --verbose --rev
[pager]
attend = diff,status,log,qdiff,blame,annotate,pdiff,glog,show

The pager configuration is necessary because by default pager only works on a whitelist of commands, so you need to add this new show alias. Then you can simply use it like hg show tip to view the contents of your topmost mq patch.

I’ve only tested this configuration on Ubuntu 12.04 with Mercurial 2.0.2, so I’d be interested to hear if it works elsewhere.

4 Responses to “Prettier Mercurial output”

  1. David Zbarsky Says:

    This works on OSX.
    Thanks, it’s pretty awesome.

  2. Steve Fink Says:

    I feel like a dork promoting my extension this way, but I use the qshow command from https://bitbucket.org/sfink/mqext (aliased to show). You still have to add the attend= part, but it’ll show you to topmost applied patch with no args, you can use either patch names or indexes (from |hg qseries -v|), and it’ll work on (and colorize) unapplied patches if you request them by name. It does not however work for patches in the repo history.

    I suppose that doesn’t even make sense for something named qshow. Hmm… but I alias it to show, and it makes sense for that, so I think I’ll implement that anyway. Done.

  3. Coop Says:

    Seconded. Love the alias for show.

  4. Steve Fink Says:

    Thinking about it again, isn’t this the same as |hg diff -c|?