14 January 2010

Colourizing mercurial output when piping to less

Filed under: Uncategorized — Tags: — bookweevil @ 10:43 am

From at least version 1.3.1 onwards, it looks like mercurial will colourize the output of commands like “hg diff” (for instance), making them much easier to read on-screen.

However, when it detects that output is going to a pipe rather than a terminal, it normally turns colourization off.

You can turn it back on using the “–color=always” argument; and if you’re piping to “less”, then “less -R” will cause it to recognize ANSI colour escape sequences. For example:

  hg diff --color=always | less -R

Blog at