Skip to content

Instantly share code, notes, and snippets.

@ChimeraCoder
Created April 30, 2018 18:27
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 ChimeraCoder/9b8218808f11e05e12b1e85b786ab898 to your computer and use it in GitHub Desktop.
Save ChimeraCoder/9b8218808f11e05e12b1e85b786ab898 to your computer and use it in GitHub Desktop.
exit code in bash prompt
ps1_prompt() {
local ps1_exit=$?
if [ $ps1_exit -eq 0 ]; then
#ps1_status=`echo -e "\[\033[32m\]"'\$'"\[\033[0m\]"`
ps1_status='\$'
else
ps1_status=`echo -e "\[\033[1;31m\]"'\$'"\[\033[0m\]"`
fi
ps1_git=''
PS1="${debian_chroot:+($debian_chroot)}\u@\h:\[\033[01;34m\]\w\[\033[00m\]${ps1_git}${ps1_status} "
PS1="\[\e[1;31m\][\u@\h \w] (${ps1_exit}) \$\[\e[0m\] "
}
# preserve earlier PROMPT_COMMAND entries...
PROMPT_COMMAND="ps1_prompt;$PROMPT_COMMAND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment