Stderr – zsh

Zsh is a great shell that simplifies a lot of tasks and brings in a ton of features (if you intend to use a load of modules and shell functions that is). For instance, the live command coloring capability is pretty awesome. The following post is just a simple illustration of a simple, single line added to my .zshrc and what it does.

When you type in a wrong command, the shell will throw a stderr command not found. The output would be the same color as the foreground color that you use on your terminal (The command color is red here because of live command highlighting – More on this at the end of the post). Like this:

Stderr - Default

But, wouldn’t it be nice to color the output as well? I want my colors man. See what I mean?

Stderr - Colored

All I had to do was add a line in my .zshrc on my BSD boxes.

Line in .zshrc

It should be self-explanatory I guess. Here’s the entry again for you Ctrl+C, Ctrl+V ‘ers.

exec 2>>( while read X; do print "\e[91m${X}\e[0m" > /dev/tty; done & )

With live command coloring, colored stderr is repetitive though. Since, typing a wrong command would automatically let the command stand out in red, indicating that it is not a proper command. But if you don’t want live syntax highlighting, the above feature would be of use.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s