Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: coloring STDERR to terminal



On Sun, 27 Jun 2004, Atom 'Smasher' wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> i'm not sure if this is possible without patching some sources, but here's
> what i want to do... every time STDERR is directed to a terminal, i want to
> filter it through _something_like_ this:
> 	awk '{print "^[[91m"$0"^[[0m"}'

This sort of thing is the reason that zsh's coprocess hangs around after 
its input and output are closed, rather than exiting the way ksh coprocs
do.  Assuming you're not using the coprocess for anything else (hardly
anyone does) you can do this:

 coproc while read line; print '\e[91m'${(q)line}'\e[0m' > /dev/tty
 exec 2>&p

(Oh, that also assumes that the "shortloops" option is set.  Insert a "do"
and end with ";done" if you don't have that setopt.)

It's better to use a zsh while-loop than something like awk because most 
filter programs will wait for a full input buffer before processing and 
for a full output buffer before printing, but here you want each line to 
be processed and printed immediately.



Messages sorted by: Reverse Date, Date, Thread, Author