7
2
When you pipe something through less
, the program usually discards color codes because it's not outputting to a TTY. So you have to add --color=always
to the options for it to work.
ls -l --color=always | less
grep -R asdf --color=always | less
What's worse is that sometimes things don't even support that option, so there's actually no way to force color output to a pipe.
Is there a (relatively) easy way to make less emulate a TTY so that I don't have to specify --color=always
to every program when things get piped to it, and it automatically displays color output when possible?
1I don't ever recall seeing a TTY that printed in other than black. – Daniel R Hicks – 2012-02-03T23:10:16.107