Color your terminal return codes

Any program you run outputs a return-code when it stops to tell the system whether it was successfull (including ‘terminal commands’ like ls, which is actually also a program). I use the terminal a lot so I appreciate things that make it even better – like for example coloring the terminal return codes that can be seen in the screenshot below. 

Image

The color that prefixes the input field reflects the return code of the last command executed. 

It was inspired by a comment this blog about coloring the terminal shell.
You get it by adding the following to your .bashrc (afterwards you have to restart your terminal) 

# Success / failure indications for return code of job.
OLDPS1=$PS1
PASS=' '
FAIL=' '
SEGV='X'
CLEAR='\e[0m'
RED="${CLEAR}\[\e[41m\]"
GREEN="${CLEAR}\[\e[42m\]"
WHITE="\[\e[0m\]"

PS1="\`RC=\$?; if [ \$RC = 0 ]; then echo ${GREEN}${PASS}${WHITE}; elif [ \$RC = 139 ]; then echo ${RED}${SEGV}${WHITE}; else echo ${RED}${FAIL}${WHITE}; fi\` $OLDPS1"