#!/bin/bash # A script to indicate a nonzero return code from a command by # changing the next prompt. If a command sneakily fails without # providing any indication other than its return code, your prompt # changes to let you know, for example: # # joe@acomputer$ true | false | true # joe@acomputer Ouch! 0 1 0 $ # # For use with the bash variable PROMPT_COMMAND, e.g. in .bashrc: # set -o pipefail # PROMPT_COMMAND='eval $(/usr/local/bin/setprompt ${PIPESTATUS[@]})' RETCODE="$*" && history -a if [ "$RETCODE" = "0" ] then SQUEAL="" elif [[ "$RETCODE" == *[1-9]* ]] then SQUEAL=" Ouch! $RETCODE " fi echo "PS1='\\u@\\h$SQUEAL\\$ '"