Skip to content

Instantly share code, notes, and snippets.

@yosshi
Forked from uasi/gist:214109
Created November 9, 2009 11:06
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 yosshi/229874 to your computer and use it in GitHub Desktop.
Save yosshi/229874 to your computer and use it in GitHub Desktop.
#
# Show branch name in Zsh's right prompt
#
autoload -Uz VCS_INFO_get_data_git; VCS_INFO_get_data_git 2> /dev/null
function rprompt-git-current-branch {
local name st color gitdir action
if [[ "$PWD" =~ '/¥.git(/.*)?$' ]]; then
return
fi
name=`git branch 2> /dev/null | grep '^¥*' | cut -b 3-`
if [[ -z $name ]]; then
return
fi
gitdir=`git rev-parse --git-dir 2> /dev/null`
action=`VCS_INFO_git_getaction "$gitdir"` && action="($action)"
st=`git status 2> /dev/null`
if [[ -n `echo "$st" | grep "^nothing to"` ]]; then
color=%F{green}
elif [[ -n `echo "$st" | grep "^nothing added"` ]]; then
color=%F{yellow}
elif [[ -n `echo "$st" | grep "^# Untracked"` ]]; then
color=%B%F{red}
else
color=%F{red}
fi
echo "$color$name$action%f%b "
}
setopt prompt_subst
RPROMPT='[`rprompt-git-current-branch`%~]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment