Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hmcfletch
Forked from joshmvandercom/git_prompt.sh
Created May 10, 2011 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmcfletch/965595 to your computer and use it in GitHub Desktop.
Save hmcfletch/965595 to your computer and use it in GitHub Desktop.
Git prompt
DEFAULT="\[\033[1;00m\]"
BLACK="\[\033[1;30m\]"
YELLOW="\[\033[1;33m\]"
GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
BLUE="\[\033[1;36m\]"
# Returns "*" if the current git branch is dirty.
function parse_git_dirty {
[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]] && echo "*"
}
# Returns "|shashed:N" where N is the number of stashed states (if any).
function parse_git_stash {
local stash=`expr $(git stash list 2>/dev/null| wc -l)`
if [ "$stash" != "0" ]
then
echo "|stashed:$stash"
fi
}
# Get the current git branch name (if available)
git_prompt() {
local ref=$(git symbolic-ref HEAD 2>/dev/null | cut -d'/' -f3)
if [ "$ref" != "" ]
then
echo "($ref$(parse_git_dirty)$(parse_git_stash)) "
fi
}
export PS1="[$GREEN\u:$YELLOW\w$DEFAULT]$BLUE \$(git_prompt)\$ $DEFAULT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment