Skip to content

Instantly share code, notes, and snippets.

@ChimeraCoder
Created Apr 30, 2018
Embed
What would you like to do?
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