Skip to content

Instantly share code, notes, and snippets.

@KevinGimbel
Forked from mislav/bash_profile.sh
Created November 17, 2015 09:48
Show Gist options
  • Save KevinGimbel/755d3bcf86ffa97f2ef3 to your computer and use it in GitHub Desktop.
Save KevinGimbel/755d3bcf86ffa97f2ef3 to your computer and use it in GitHub Desktop.
Simple bash prompt that shows current git branch (if any) and colors the dollar sign in red if the last command exited with a nonzero status.
_git_prompt() {
local ref="$(command git symbolic-ref -q HEAD 2>/dev/null)"
if [ -n "$ref" ]; then
echo " (${ref#refs/heads/})"
fi
}
_failed_status() {
[ "$PIPESTATUS" -ne 0 ] && printf "$"
}
_success_status() {
[ "$PIPESTATUS" -eq 0 ] && printf "$"
}
PS1='\[\e[0;31m\]\w\[\e[m\]$(_git_prompt) \[\e[1;31m\]$(_failed_status)\[\e[m\]$(_success_status) '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment