How to display color by piping command to less

colorsless

When I use:

msgattrib --untranslated pl.po

to see untranslated strings from po file I've got strings in color, but not when I use:

msgattrib --untranslated pl.po | less

Best Answer

msgattrib display colors only if executed from real terminal. You can use unbuffer command that's part of expect to make msgattrib think that it's executed from real terminal and then use -r option to handle ANSI escapes in less:

unbuffer msgattrib --untranslated pl.po | less -r

You can do that in any command that produce colors (ANSI escapes codes) based on existance of tty.

Related Question