My BASH prompt

The $PS1 of the future

I have my own BASH prompt. Copy the code below to your .bashrc file to see it in action.

PROMPT_COMMAND='EXCO=$?;pwdw=$(expr $(tput cols | tr -d '\n') - 25 | tr -d '\n')' PS1='$(if [ $EXCO == 0 ]; then echo -ne "\[\033[42m\]\[\033[01;30m\]"; else echo -ne "\[\033[41m\]\[\033[01;34m\]"; fi)$(length-extra-prepend $EXCO 3)\[\033[45m\] \[\033[44m\]\[\033[01;37m\]$(date +%H:%M)\[\033[45m\] \[\033[46m\]\[\033[01;32m\]$(length-too-much-shorten "$(pwd | sed s%$HOME%~%)" $(if (( $pwdw < 20 )); then echo -n 20; else echo -n $pwdw; fi))\[\033[00m\]\n\[\033[45m\]\[\033[01;33m\]\u\[\033[01;32m\]@\[\033[01;36m\]\h\[\033[43m\]\[\033[01;30m\]:\[\033[40m\]\[\033[01;33m\]\$\[\033[00m\] '

You'll also need to download bash-prompt-extras.tar.gz, which contains trivial code that is needed to show my BASH prompt correctly. More specifically, you should put the two programs from the archive into a directory that is in your $PATH. This can either be done by moving them to /usr/local/bin/ or placing them in a directory that you do not move, which you then add to your path by appending the following line to your .bashrc file:

export PATH=$PATH:/your/dir

 

That should do it.

Last updated: 20 Jan 2010