Skip to content

Instantly share code, notes, and snippets.

@charlesthomas
Last active August 29, 2015 13:57
Show Gist options
  • Save charlesthomas/9696225 to your computer and use it in GitHub Desktop.
Save charlesthomas/9696225 to your computer and use it in GitHub Desktop.
color prompt based on exit status of previous command
NONE="\e[0m"
RED="\e[0;31m"
GREEN="\e[0;32m"
function last_exit_prompt() {
if [[ $? -eq 0 ]]; then
PS1="${PS1}\n\[${GREEN}\]>> \[${NONE}\]"
else
PS1="${PS1}\n\[${RED}\]>> \[${NONE}\]"
fi
}
PROMPT_COMMAND="last_exit_prompt;$PROMPT_COMMAND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment