Skip to content

Instantly share code, notes, and snippets.

@ianloic
Created June 25, 2011 19:55
Show Gist options
  • Save ianloic/1046832 to your computer and use it in GitHub Desktop.
Save ianloic/1046832 to your computer and use it in GitHub Desktop.
Showing the Git module and status
setopt prompt_subst
autoload colors zsh/terminfo
colors
function __git_prompt {
local DIRTY="%{$fg[yellow]%}"
local CLEAN="%{$fg[green]%}"
local UNMERGED="%{$fg[red]%}"
local RESET="%{$terminfo[sgr0]%}"
git rev-parse --git-dir >& /dev/null
if [[ $? == 0 ]]
then
echo -n "["
if [[ `git ls-files -u >& /dev/null` == '' ]]
then
git diff --quiet >& /dev/null
if [[ $? == 1 ]]
then
echo -n $DIRTY
else
git diff --cached --quiet >& /dev/null
if [[ $? == 1 ]]
then
echo -n $DIRTY
else
echo -n $CLEAN
fi
fi
else
echo -n $UNMERGED
fi
echo -n `git branch | grep '* ' | sed 's/..//'`
echo -n $RESET
echo -n "]"
fi
}
export RPS1='$(__git_prompt)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment