Two and a half years ago, I wrote a PS1 which renders current working directory with colors and abbreviate directory names. Today, I recoded it a bit.

http://farm3.static.flickr.com/2049/2140298262_f6f0d3b090_o.png

Old PS1

http://farm5.static.flickr.com/4039/4664700598_e6da3e7c09_b.jpg

New PS1

Screenshot on top is the old one. You can see this diff view of my .bashrc. Generally, the newer one has same result, I only added color to the ~. I used the newer Bash syntax [[]] and (()) instead of the old test [].

My original plan was to use C code, unfortunately, those escape code, \[, \], or \e, must not be from $variable or results from subshell, they have to be apparent strings in PS1. If you know how to resolve this issue, please let me know. If you only want to shorten PWD and do not need these fancy colors, there is an one-liner1 version.

Two and a half years, many things have changed, you just can see from the screenshots. I have switched to Gentoo from Fedora, GNOME to Fluxbox, GNOME Terminal to urxvt, GNU/Screen to tmux (this didn’t show in screenshot), eyecandy (Compiz Fusion, IIRC) to plain, mainly use CLI. I used to run su -, now I just sudo. And the kernel version from 2.6.23 to 2.6.32.

Many things have changed.

[1]https://bbs.archlinux.org/viewtopic.php?pid=767150#p767150 is gone.