Skip to content

Instantly share code, notes, and snippets.

@AnrDaemon
Created June 24, 2017 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnrDaemon/2148402d96faae335bb762b280554f3a to your computer and use it in GitHub Desktop.
Save AnrDaemon/2148402d96faae335bb762b280554f3a to your computer and use it in GitHub Desktop.
__set_prompt()
{
test "$PS_ORIG" || PS_ORIG="$PS1"
test "$PC_ORIG" || eval "PC_ORIG='$PROMPT_COMMAND'"
PROMPT_COMMAND=__bash_prompt
}; readonly -f __set_prompt
__bash_prompt()
{
local ERRORLEVEL=$?
if [ $ERRORLEVEL != 0 ]; then
ERRORLEVEL="\n[$(tput setaf 1)$ERRORLEVEL$(tput sgr0)]"
else
ERRORLEVEL=
fi
eval "$PC_ORIG"
[ "$PS_ORIG" ] && PS1="$ERRORLEVEL$PS_ORIG"
}; readonly -f __bash_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment