Saturday, August 27, 2011

My bash prompt

Here's my bash prompt (in ~/.bashrc):
PS1="\[\033[1;32m\]$(date +%H:%M)\[\033[0m\]:\[\033[1;34m\]\W\[\033[0m\]$ "

For an explanation of the control codes (the parts that look like gibberish), go here.

The result looks something like this:
16:29:Downloads$

In other words, it shows the time and the name of the directory I'm currently in (not the full path; if I need that, I can just run pwd)

Most prompts show the user and/or machine name, which is probably a good default, but I usually don't care about it so much. What I found far more useful in multi-machine situations with command prompts was to change the color of the timestamp (e.g. my laptop was green, my home server was yellow, various school machines were white), since I'm personally much more likely to notice differences in color than differences in name.

I also find the time to be useful in a variety of situations (e.g. how long did that command take to run? when was the last time I built?)

You can certainly do more elaborate prompts with all kind of information in them, but I like mine because it's very compact and leaves lots of space, even in 80-char windows