Skip to content

Instantly share code, notes, and snippets.

@mislav
Created January 24, 2014 17:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mislav/8602351 to your computer and use it in GitHub Desktop.
Save mislav/8602351 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