BASH prompt return code visualization

I like to have a pretty obvious indication of the success of failure of any commands I might have run, so as part of my BASH prompt I include a color coded display of the return code using the following:
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NOFORMAT='\033[m'

#return code visualisation
RVAL='$(RET=$?; if [[ $RET -eq 0 ]]; then echo -ne "$GREEN"; else echo -ne "$RED"; fi; echo -ne "$RET$NOFORMAT")'
I then include that as a part of my $PS1 in my .profile:
# prompt
PS1="$BLUE\t \h \$PWD $RVAL\r\n\\$ "
That gives me a prompt that looks like this for root after a successful command: 11:57:24 MyBox /root 0 # or like this for a normal user after a failed command (CTRL-C in this case): 11:57:24 MyBox /home/user 130 $

Tags: