Customized Bash Prompt

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

  • http://maketecheasier.com/8-useful-and-interesting-bash-prompts/2009/09/04
  • http://tldp.org/HOWTO/Bash-Prompt-HOWTO/

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!).

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>