Showing Last Error Code in Bash Prompt

A good way of spotting problems with scripts early on is to keep an eye on their exit codes. This tiny change to your PS1 prompt, in .bashrc or, better, .bash_aliases, adds an error code if and only if it is non-zero:

    if [ $1 != 0 ]; then
        echo -n -e " $1";

PS1='\t ${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\H\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]`check_for_error \$?`> '

The above shows my current prompt, which also includes the current time, including seconds, when the prompt appeared.