Skip to content

Instantly share code, notes, and snippets.

@shishi
Forked from uasi/gist:214109
Created April 20, 2012 06:19
Show Gist options
  • Save shishi/2426545 to your computer and use it in GitHub Desktop.
Save shishi/2426545 to your computer and use it in GitHub Desktop.
#
# Show branch name in Zsh's right prompt
#
autoload -U colors; colors
function rprompt-git-current-branch {
local name st color
name=`git branch 2> /dev/null | grep '^¥*' | cut -b 3-`
if [[ -z $name ]]; then
return
fi
st=`git status`
if [[ -n `echo "$st" | grep "^nothing to"` ]]; then
color=${fg[green]}
elif [[ -n `echo "$st" | grep "^nothing added"` ]]; then
color=${fg[yellow]}
elif [[ -n `echo "$st" | grep "^# Untracked"` ]]; then
color=${fg_bold[red]}
else
color=${fg[red]}
fi
echo "%{$color%}$name%{$reset_color%} "
}
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