I am trying to make less output colored for a while. I have read everything how to do that, and tried all, but none worked. Things I have tried: export LESS="-R" tried export LESSCOLOR="always" and export LESSCOLOR="yes" tried both export LESSOPEN='|lesspipe.sh %s', and unset LESSOPEN The result was always the same: echo "asdqwe" | grep --colour=auto "asd" :: Colored output. echo "asdqwe" | grep --colour=auto "asd" | less -R :: Colorless output. Man and all the other programs has colors which use less as pager, but when i append `` | less -R '' to command line, the output becomes black'n'white, and can't change that. Nobody has written anything else than to change this variables to make less inherit colors to output.
grep --colour=auto only uses colouring when the output is a tty. When you pipe the output through another program, colours will be suppressed. The same thing will happen if you pass the output to cat.
But this happens not only with grep, but with any other colored input i redirect. emerge, eix, or try to save it. So this is how colors are handled? if not going to tty, then suppressed? What reason has less -R then? Do you think this is a good solution? Well maybe for you it is. But not for me. But then, could you give me a guide where to start to make gentoo not to delete color codes from output if not going to tty? This could result a nice review of emerge log-s, eix lists - where colors are VERY important -, greps and stuff like that. I know this will lead to unexpected results for example in pattern matching. Will take the risk. But still I don't think this is the way it should work.
most utilities out there will disable color output automatically if the output is not a tty. this is the expected design behavior. if you dislike it, you can force each utility to display color in the output. read the relevant documentation for each utility (such as grep --color=always). there's nothing to be "fixed" here.