stderr in red.
stderred hooks on write() function from libc in order to colorize all stderr output that goes to terminal thus making it distinguishable from stdout. Basically it wraps text that goes to file with descriptor "2" with proper escape codes making text red.
It's implemented as a shared library and doesn't require recompilation of
existing binaries thanks to
LD_PRELOAD feature of Linux dynamic linker.
Clone this repository:
git clone git://github.com/sickill/stderred.git cd stderred
For 32-bit system:
For 64-bit system:
You can enable stderred in 2 ways.
Recommended one is to export
LD_PRELOAD variable in your shell's config file.
Put following in you .bashrc/.zshrc:
if [ -f "/absolute/path/to/lib/stderred.so" ]; then export LD_PRELOAD="/absolute/path/to/lib/stderred.so" fi
Second option is to create alias and then use it to selectively colorize stderr for run commands:
$ alias stderred='LD_PRELOAD=/absolute/path/to/lib/stderred.so' $ stderred java lol
Make sure that path to
stderred.so is absolute!
Checking if it works
$ python -c 'import os; print "Yo!"; os.write(2, "Jola\n\r")'
Jola should be in red dress.
* Ignore this section if using Ubuntu. Ubuntu prefers architecture purity and doesn't allow coexisting 32 and 64-bit packages on the same installation. Thus this problem doesn't exist on this distro.
On some Linux distros you can run 32-bit binaries on 64-bit system. Shared
libraries compiled for 64-bit doesn't work with 32-bit binaries though. It
happens that 64-bit binaries call 32-bit ones resulting in warning message
printed to terminal about not compatible
LD_PRELOAD shared lib.
Fortunately Linux's dynamic linker has a feature called Dynamic String Token
(DST). It allows dynamic substitution of
$LIB token in
with "lib" or "lib64" respectively for 32 and 64-bit binaries when the binary
is being run.
Thanks to that you can compile stderred for both architectures and automatically use proper version of this shared library.
On Fedora, for example, you need to install libc development headers for both architectures:
$ sudo yum install glibc-devel.i686 glibc-devel.x86_64
compile it like this:
$ make both
LD_PRELOAD like this in your shell's config:
Simpler and much less reliable solution when using Zsh is to use named pipes trick proposed on Gentoo Linux wiki. It has some race condition/buffering issues and breaks on interactive commands writing to stderr though.
Marcin Kulik - current implementation
You are free to use this program under the terms of the license found in LICENSE file.