[TriLUG] colorize stderr in bash
brphelps at ieee.org
Wed Jul 23 17:37:15 EDT 2008
Thats interesting, not worried about doing it with files or certain
commands, I think I can figure out how to do that with sed.
I guess I'm looking for the short quick answer to "What line can I add
to .bashrc to get colorized stderr"
I found one for zcsh, but I don't know how to get my shell, bash to do
something similar when I log in interactively.
On Wed, 2008-07-23 at 17:19 -0400, Kevin Hunter wrote:
> At 4:28p -0400 on Wed, 23 Jul 2008, Brian Phelps wrote:
> > Is there an easy way to colorize stderr in an interactive bash shell?
> Obligatory disclaimer: be wary of using colors in the terminal. Not all
> terminals/emulators are created equal, nor are ANSI escape sequences
> portable. Colorized output that looks absolutely splendid on one
> author's machine may be barely readable on another's. (e.g. Yellow text
> on black, and white backgrounds.) Also, be aware that a significant
> portion of the population is colorblind, and for which colors have the
> opposite effect they might have for you.
> Long answer:
> That said, I prefer colors and think they're currently underutilized in
> the industry. For those who *aren't* color blind, and who use ANSI
> capable terminals emulators colors can help identify breaks in longs
> scrolls of largely superfluous output text, or bring out warning or
> error messages. For example, a tail of a web log and highlighting 404s
> (NOT FOUND), or 500s (SERVER ERROR)*, or parsing debug, informational,
> and warning messages from a compiler, or running program. Some folks
> even colorize their command prompt.
> Examples of programs in the wild that colorize (some) of their output
> django, pulseaudio. I have found that the lightred lines move my eye
> directly where they need to be, and now I know what they mean; I don't
> have to reread them everytime to know what's up.
> If you're worried about portability and playing-nice-with-others, I
> would caution you to make an *easy* opt-in or opt-out preference for
> those who do(n't) want colors.
> Short answer: the same way you'd do it with stdout: with escapes.
How do I get the shell to do it interactively?
> Some projects you might want to peruse:
> * Obviously, you don't want to clutter the logs with escape sequences,
> but what about piping to another program, e.g.
> $ tail -f log | http-colorizer
<a href=http://electronjunkie.wordpress.com>Got e-?</a>
More information about the TriLUG