Skip to content

Instantly share code, notes, and snippets.

@avit
Created April 14, 2010 21:24
Show Gist options
  • Save avit/366359 to your computer and use it in GitHub Desktop.
Save avit/366359 to your computer and use it in GitHub Desktop.
# prompt for showing current git branch and dirty state:
__git_branch_status() {
local b
local d
if ! [[ $(git status 2> /dev/null) ]]; then
return
fi
if ! b="$(git symbolic-ref HEAD 2>/dev/null)"; then
if ! b="$(git describe --exact-match HEAD 2>/dev/null)"; then
b="$(git rev-parse 2>/dev/null | cut -c1-7)..."
fi
fi
if [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]]; then
d="*"
fi
echo "(${b##refs/heads/})$d"
}
export PS1='\u@\h \[\033[1;33m\]\w\[\033[0m\]$(__git_branch_status) $ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment