Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Operating system: Mac OS 10.6.2

I'd like to be able to see colour output when piping certain commands through less.

Two examples:

I've got ls aliased to ls --color=auto, so I'd like to be able to see colour when I do this:

ls -l | less

I've also got the color extension turned on in Mercurial, so I'd like to see colour output from:

hg diff | less


hg st | less

After some googling, it seems like some versions of less support either -r or -R to make this work, but no dice for me. I can't see anything in the man page that looks like what I need. (-r or -R SEEM to be the right options, but again, they don't seem to work)

share|improve this question

migrated from Mar 27 '10 at 21:01

This question came from our site for professional and enthusiast programmers.

It looks like the color extension is always disabled when piped. Try these commands to see what I mean: ls --color=always | ls -R and hg diff --config color.mode=ansi | less -R – Harvey Aug 10 '10 at 17:34
up vote 26 down vote accepted

For mercurial, you should use the pager extension rather than piping explicitly to less. This will play nicely with the colored output options of other hg commands.

share|improve this answer

I believe you have to use --color=always for ls if you want it to do colors even when not going to stdout. Then use -r on the less command

ls --color=always -l | less -r
share|improve this answer


$ hg diff --color always | less -R

I would alias "less -R" to less. I'm not sure if there's a way to provide default options to mercurial's commands so that you don't have to remember to type --color always for hg diff all the time.

share|improve this answer
Or use $ hg diff --color always | less -FRSXQ for better less options. It will silently quit if diff fits the screen, for example. – jpbochi Jul 28 '12 at 15:08
You can setup LESS="-R" alternatively to aliasing "less" itself. – blueyed Sep 27 '12 at 10:45
-F is to keep reading file as it's being produced, -S is to not line-wrap, -X something obscure, -Q avoids ringing terminal bell. – Evgeni Sergeev Jan 23 '14 at 0:17

In your ~/.hgrc put:

color =
pager =

pager = LESS='FRSXQ' less
quiet = True
attend = outgoing,incoming,diff,status,log,qdiff,blame,annotate,pdiff,glog
share|improve this answer

If you don't want to use the Pager Extension for mercurial you can use the following command:

hg diff | cdiff
share|improve this answer

ls --color=auto means you get colour output when it's not being piped to something. Try ls --colour=auto | cat and you'll see what I mean.

I expect hg makes similar assumptions.

share|improve this answer

[defaults] diff = --color always

share|improve this answer
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – Ramhound Jul 2 at 19:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .