Skip to content

Instantly share code, notes, and snippets.

@drock
Created October 8, 2012 21:31
Show Gist options
  • Save drock/3855121 to your computer and use it in GitHub Desktop.
Save drock/3855121 to your computer and use it in GitHub Desktop.
Bash prompt to show current git status and branch
#Install git-core +bash_completion
#sudo port install git-core +bash_completion
#paste this into your .bash_profile
#customize the PS1 variable as desired
GIT_PS1_SHOWUPSTREAM="verbose"
if [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then
. /opt/local/etc/profile.d/bash_completion.sh
fi
source /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh
function parse_git_dirty {
git diff --quiet HEAD &>/dev/null
[[ $? == 1 ]] && echo "⚡"
}
function parse_git_branch {
local branch=$(__git_ps1 "%s")
[[ $branch ]] && echo "[$branch$(parse_git_dirty)]"
}
export PS1="$GREEN\u@\h $RED\w $YELLOW\$(parse_git_branch)\[\033[00m\] \$"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment