"more" command alternative that does support colors?

Avio picture Avio · May 27, 2012 · Viewed 9.5k times · Source

This is in my top 10 list of tiny annoying things in Linux. I love colored output in terminals: it's nice to see and useful when reading.

The first thing I do on a new system is to set aliases for both ls and grep to show colored output, and the second is to install vim and htop.

I use both Gentoo and Ubuntu, and I see that emerge, the package manager of Gentoo, has a higher readability than apt-get/aptitude just because it uses way much more color output than the latter.

So, whenever I have to pipe an emerge command with more, all the color is lost and I have to focus my attention on every line to avoid missing anything important.

I can understand that a basic command such as more shouldn't depend on ncurses (someone could argue that we also have less, so one of the two could be even color-friendly), but why there isn't a famous alternative to more that supports colors, as there is for vi/vim, top/htop etc.?

Thanks for any hint.

Answer

rodrigo picture rodrigo · May 27, 2012

Most commands that can output color have an option to choose between:

  • ON: Always output color
  • OFF: Never output color
  • AUTO: Show color if and only if the output is a terminal

Many commands work automatically in color AUTO mode. That is the case for emerge. And that is why you do not have color when you pipe the output: the pioe is not a terminal.

The solution is to tell emerge to output the colors unconditionally. And tell less not to filter them, of course.

Try:

emerge --color y | less -R