Customized Bash Prompt

The following sites inspired me to explore creating a customized prompt (for bash):

So here is mine:

PS1="\$(if [[ \$? != "0" ]]; then echo \[\e[31m\]; fi)\n\$(date)\n\\[\e[1m\\]\[\$(dirs)\]\n\\[\e[m\\]"
PS2=""

Features:

  • Color change on error return code
  • The current date
  • The current directory stack (I use pushd and popd)
  • Commands start on their own line

And that’s it!  I really don’t need the prompt to tell me what my username is or the hostname of the machine (duh!).