• Stars
    star
    990
  • Rank 46,251 (Top 1.0 %)
  • Language
    C
  • License
    MIT License
  • Created about 13 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

stderr in red

stderred

stderr in red.

About

stderred hooks on write() and a family of stream functions (fwrite, fprintf, error...) 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 ANSI escape codes making text red.

It's implemented as a shared library and doesn't require recompilation of existing binaries thanks to preload/insert feature of dynamic linkers.

It's supported on Linux (with LD_PRELOAD), FreeBSD (also LD_PRELOAD) and OSX (with DYLD_INSERT_LIBRARIES).

Watch this intro asciicast to see it in action.

Installation

Clone this repository:

$ git clone git://github.com/sickill/stderred.git
$ cd stderred

Important: In all cases below make sure that path to libstderred.so is absolute!

Linux and FreeBSD

Make sure you have cmake and the gcc toolchain required for compilation installed:

# Ubuntu
sudo apt-get install build-essential cmake

# Fedora
sudo yum install make cmake gcc gcc-c++

# FreeBSD
pkg install cmake

Build:

$ make

Export LD_PRELOAD variable in your shell's config file by putting following in your .bashrc/.zshrc:

export LD_PRELOAD="/absolute/path/to/stderred/build/libstderred.so${LD_PRELOAD:+:$LD_PRELOAD}"

Multi-arch Linux and FreeBSD

On some Linux distros you can install 32-bit packages 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 LD_PRELOAD variable 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 64-bit 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 32 && make 64

and export LD_PRELOAD like this in your shell's config:

export LD_PRELOAD="/path/to/stderred/\$LIB/libstderred.so${LD_PRELOAD:+:$LD_PRELOAD}"

* Note that there is no support for $LIB token on Ubuntu.

OSX

$ make

Export DYLD_INSERT_LIBRARIES variable in your shell's config file by putting following in your .bashrc/.zshrc:

export DYLD_INSERT_LIBRARIES="/absolute/path/to/build/libstderred.dylib${DYLD_INSERT_LIBRARIES:+:$DYLD_INSERT_LIBRARIES}"

Universal lib on OSX

OSX solves multi-arch problem (described above in "Multi-arch Linux and FreeBSD") by supporting so called "universal" libraries that include 2 copies of code compiled for both 32 and 64-bit architecture in the single library file.

If you feel you will want universal library then build it this way:

$ make universal

and export shell env like above.

Checking if it works

$ find -q
$ cat nonexistingfile
$ ls nonexistingfile
$ python -c 'import os; print "Yo!"; os.write(2, "Jola\n\r")'
$ STDERRED_ESC_CODE=$(echo -e '\e[;92m') ruby -e 'puts "Yo!"; warn "Jola"'

"Jola" should be printed in red color.

Alternative way: aliasing

Alternative to enabling it globally via shell config is to create alias and use it to selectively colorize stderr for the commands you run:

$ alias stderred="LD_PRELOAD=/absolute/path/to/build/libstderred.so\${LD_PRELOAD:+:\$LD_PRELOAD}"
$ stderred java lol

Configuration

Custom color code

If you prefer other color or you want to use additional escape codes (for bold/bright, italic, different background) you can export STDERRED_ESC_CODE with desired escape code sequence.

Here's an example for bold red:

bold=$(tput bold || tput md)
red=$(tput setaf 1)
export STDERRED_ESC_CODE=`echo -e "$bold$red"`

Program Blacklisting

Some programs abuse stderr and print stuff on it even when they really shouldn't. If you want to turn off stderred for particular programs you can export STDERRED_BLACKLIST with a desired POSIX Extended Regular Expression matching names of these programs.

Here's an example that will blacklist bash, and all programs with names starting with "test":

export STDERRED_BLACKLIST="^(bash|test.*)$"

Authors

Current implementation:

Original concept and initial implementation:

  • Asheesh Laroia

License

You are free to use this program under the terms of the license found in LICENSE file.

More Repositories

1

vim-monokai

Monokai color scheme for Vim converted from Textmate theme
Vim Script
1,434
star
2

bitpocket

"DIY Dropbox" or "2-way directory (r)sync with proper deletion"
Shell
1,029
star
3

git-dude

Git commit notifier
Shell
948
star
4

rainbow

Ruby gem for colorizing printed text on ANSI terminals
Ruby
810
star
5

racksh

Console for Rack based ruby web apps
Ruby
424
star
6

vim-pasta

Pasting in Vim with indentation adjusted to destination context
Vim Script
321
star
7

coloration

Textmate to Vim, JEdit and Kate/KWrite color scheme converter
Ruby
260
star
8

css2less

Css to LessCss converter
Ruby
62
star
9

off-plugin

Plugin for Netbeans and JEdit for quick finding and opening files by typing just few characters
Java
44
star
10

vim-sunburst

Sunburst color scheme for Vim converted with coloration.ku1ik.com from Textmate theme with the same name.
Vim Script
28
star
11

dotfiles

My virtual home
Vim Script
27
star
12

rack-revision-info

Rack middleware showing current git (or svn) revision number of deployed application
Ruby
20
star
13

rack-lesscss

Rack middleware for serving LessCSS files compiled to CSS
Ruby
14
star
14

tm2jed

Texmate-To-JEdit colour theme converter - NOTE: DEVELOPMENT MOVED TO sickill/coloration repo
Ruby
9
star
15

kanbanery-ruby-client

Ruby client library and CLI for Kanbanery.com
Ruby
8
star
16

ps

Unix "ps" on the web.
Ruby
7
star
17

traytor

Show (animated) tray icon from command line
Python
7
star
18

example-rack-framework

Example ruby web framework built with Rack
Ruby
6
star
19

skype-kde-notifications

Displaying Skype incoming messages with KDE4 visual notifications
Python
6
star
20

homepage

Personal homepage / blog
CSS
5
star
21

coloration-web

Web frontend for Coloration
CSS
5
star
22

krug-merb-presentation

Ruby
4
star
23

rubytime-plasmoid

Rubytime plasmoid with support for adding activities and notifications
C
4
star
24

vim-git-inline-diff

Git inline diff for Vim using Vim's signs feature
Vim Script
4
star
25

vimbanery

Vim-like keybindings for Kanbanery
JavaScript
4
star
26

merb-resque-mailer

Merb plugin for putting mail delivery jobs onto Resque queue
Ruby
4
star
27

canvator

HTML5 Canvas element demo
C++
4
star
28

gratifier

Desktop notifications with Gravatars!
Shell
3
star
29

archlinux-nginx-passenger

Nginx webserver with Passenger module for Archlinux
Shell
3
star
30

blogator

My old homepage/blog created with Sinatra + Datamapper
JavaScript
3
star
31

krug-chef-presentation

JavaScript
3
star
32

sickounter

Simple Sinatra powered downloads counter
Ruby
3
star
33

euruko2010-building-frameworks-with-rack

My Euruko 2010 conference presentation about building ruby web frameworks using Rack and available middleware
JavaScript
3
star
34

yeb

Ruby
3
star
35

kodr

Programmer's editor for KDE4 written in Ruby
Shell
3
star
36

expo

Beautiful html photo album generator
Ruby
2
star
37

minion

Dead simple ruby background jobs without workers
Ruby
2
star
38

clj-bwt

Clojure implementation of Burrows-Wheeler transform (block-sorting compression)
Clojure
2
star
39

ts-hermit

JavaScript
2
star
40

openfilefast-headless

Tool to find a file in a project (dir) using fuzzy matching (this is backend only, to be used with gui frontend)
Ruby
2
star
41

ecto-preload-bug

Example project for demonstrating Ecto preload bug
Elixir
2
star
42

tsm

Ruby
2
star
43

tmux

C
2
star
44

mail_friday

Ruby
2
star
45

urack

rack + usher + warden + tilt + rack-flash + ...
Ruby
2
star
46

flash

Keep the secrets out of emails and chat history!
Elixir
2
star
47

luna

Fresh Rails app for "Setting up fresh Ubuntu server for Rails" LLP workshop
Ruby
2
star
48

omnomnom

sinatra+heroku test app
Ruby
2
star
49

finish-him

Word autocomplete (expansion) plugin for JEdit editor written in Scala
Scala
2
star
50

gts-move-on

Clojure
1
star
51

phoenix-1.3-to-dev

Elixir
1
star
52

bitflip-gen

Rust
1
star
53

bb-lb-400

1
star
54

tarpit

Tarpit for ssh/smtp/http
Rust
1
star
55

nemesis

1
star
56

chrome-browserid

JavaScript
1
star
57

gh-356

JavaScript
1
star
58

collatz-conjecture-rs

Collatz conjecture solver
Rust
1
star
59

brunch-issue

CSS
1
star