Styling Mercurial’s CLI

posted by Steve Losh on January 15, 2010

Mercurial has a great command line interface and many people use it without ever feeling the need for a GUI to manage their repositories. However, we can make it even better by taking advantage of Mercurial’s templating features.

In this tip I’m going to post some of the templates I use and show you how to use them yourself. Check out hg help templating if you want more details on how the templating actually works.

If you like what you see you can grab my templates by cloning their repository from BitBucket:

hg clone http://bitbucket.org/sjl/mercurial-cli-templates/

NOTE: I’ve customized the colors of my Terminal, so the colors will look different for you. If you like the colors I’m using you can read the blog entry I wrote about it.

Short Log

In a previous tip I described how to create an hg slog alias that can be very useful for counting changesets. With the right styling it can be useful in your day-to-day work. Here’s what the output of my hg slog command looks like:

To use this template you can edit your ~/.hgrc file to contain the following:

[alias]
slog = log --style=/full/path/to/map-cmdline.slog

Nice Log

The short log is great a quick review of the past few changesets, but for a much more detailed view of a particular changeset I’ve created an hg nlog alias, which looks like this:

To use this template you can edit your ~/.hgrc file to contain the following:

[alias]
nlog = log --style=/full/path/to/map-cmdline.nlog

Short Graphlog

The graphlog command is wonderful for reviewing the history of repositories with branches, but we can make it more compact and easier to read with another template. The result looks like this:

To use this template you can edit your ~/.hgrc file to contain the following:

[alias]
sglog = glog --style=/full/path/to/map-cmdline.sglog

Contribute

If you have any other templates you find useful, or some improvements to mine, feel free to fork the repository on BitBucket!

Mercurial’s command line interface is great, but with a little bit of work we can make it even better!