2

I'm looking for a method to have bash colorize the output from a command based on what stream it was written to the terminal from. Is there any way to get it to colorize per stream?

Like for example

stdout -> regular color
stderr -> red
program created streams that write to the terminal -> blue
HSchmale
  • 427

2 Answers2

0

While not identical to your requirements, this earlier question would be worth a read, where someone wanted to differentiate stdout/stderr by color.

How to set font color for STDOUT and STDERR

steve
  • 21,892
0

There's:

https://github.com/sickill/stderred

or you can do it from bash with something like:

rederror() { (tput setaf 1; cat ; tput sgr0) >&2; }
#Example
someCommand() { echo normal; echo error >&2; }
someCommand 2> >( rederror )

I don't think you can color non-stdout streat that go to the terminal blue from bash. It should be possible with that approach that stderred is using (but I think it only colors stderr).

Petr Skocik
  • 28,816
  • The rederror does not seem to work with any consistency. I wrote a short cpp program that writes out on the various streams avaible to it using differint methods and testing it several times there was varying results. gist – HSchmale Jul 28 '15 at 21:19