Colorize your shell

Posted by timgoh
on Tuesday, January 22

We all love syntax highlighting, but often don’t bring that love with us to our shell. Here’s a couple tips to have a useful multi-colored shell session

Shell Prompt

Add

export PS1='\[\033[1;34m\]\h\[\033[0;33m\] \w\[\033[00m\]: '

to your bashrc.

This will give you your host in blue and working directory in brown. One excellent thing to do with this is to color-code each of the servers you log in to regularly differently. That way you have an instant, easy to understand indicator of which server you are currently accessing, so that you don’t ‘rm -rf’ from the wrong shell.

To customize, the Red Hat Knowledgebase lists more options for colors, and will come in handy for the rest of this post as well.

If you want to make sense of that command, Linux.com has a quick tutorial

Searches

Came across this tip from scie.nti.st

Add

export GREP_OPTIONS='--color=auto'
export GREP_COLOR='1;33'

to your bashrc, and have matches highlighted.

Or of course you could use tools like ack or rak which have colorization built-in and are more efficient than the venerable ‘grep’.

Man pages

Get the ‘most’ command1. On Debian and derivatives it would be a straightforward

sudo apt-get install most
.

You should already have a

export PAGER=less
or similar line in your bashrc file. Change that to
export PAGER=most
Now ‘man’ a command, and find out what you’ve been missing.

Background

One of the new things I’ll be doing with ProgProg this year is writing on various practices I have accumulated over the years. I wouldn’t go so far to call them “best practices”—they are just things that work for me.

My previous company had a great habit of not ever sitting on its laurels when it came to process. We were constantly tweaking, and occasionally making significant changes to our process in an attempt to improve. I have adopted this concept for myself, and once a week I examine my work habits and pick out something I can do in a better way. I’m not promising a weekly ‘process’ post, but will be presenting anything I find extremely useful.


1 “Most” is a misnomer though. Given that thanks to geek humor “less” is better than “more”, the command should really be called “least”.

Comments

Leave a response

  1. TimonJanuary 30, 2008 @ 01:24 PM
    I have wanted one of these forever! THANKS for the great work.
  2. Tim GohFebruary 01, 2008 @ 11:05 AM
    Hey glad you found it useful Timon. I'll continually be posting tips under the 'process' tag, so do stick around!