/ PS.bash
PS.bash
 1  # Custom bash prompt via http://kirsle.net/wizards/ps1.html
 2  # TERM isn't automatically set when logging in
 3  # we shouldn't shit the bed when using tput
 4  if [[ ${TERM:-dumb} != dumb ]] ; then
 5  
 6      # TODO change the color of the name too
 7  
 8      # Generate a color between 2 and 7
 9      # 0 = black and 1 = red
10      # red is reserved for remote hosts
11      getHostNameColor(){
12  	local hostNum=$("$MY_BASH_INIT_DIR/src/str2int.py" `hostname`)
13  	expr $hostNum % 6 + 2
14      }
15  
16      # Allows setting the host color before hand
17      if [[ -z "$PS1_HOST_COLOR" ]] ; then
18  	# For ssh connections, we must know we're on a remote host
19  	# Thefore the host is red
20  	if [[ -n "$SSH_CONNECTION" ]] ; then
21  	    PS1_HOST_COLOR=1
22  	else
23  	    # As a last resort the color will be chosen randomly
24  	    PS1_HOST_COLOR=`getHostNameColor`
25  	fi
26      fi
27  
28      export PS1="\[$(tput bold)\]\[$(tput setaf 1)\][\[$(tput setaf 3)\]\u\[$(tput setaf 2)\]@\[$(tput setaf $PS1_HOST_COLOR)\]\h \[$(tput setaf 5)\]\w\[$(tput setaf 1)\]]\[$(tput setaf 7)\]\\n\\$ \[$(tput sgr0)\]"
29  fi