Skip to content

Instantly share code, notes, and snippets.

@syohex
Created July 12, 2012 12:09
Show Gist options
  • Save syohex/3097763 to your computer and use it in GitHub Desktop.
Save syohex/3097763 to your computer and use it in GitHub Desktop.
Visualize current repository is clean or not clean
## show git branch at right prompt
autoload -Uz vcs_info
zstyle ':vcs_info:*' formats '[%b]'
zstyle ':vcs_info:*' actionformats '(%s)-[%b|%a]'
precmd () {
psvar=()
LANG=en_US.UTF-8 vcs_info
is_fine=0
[[ -n "$vcs_info_msg_0_" ]] && psvar[1]="$vcs_info_msg_0_"
if git rev-parse --is-inside-work-tree >/dev/null 2>&1
then
if test -z "$(git status --porcelain)"
then
is_fine=1
psvar[2]='☀ '
else
psvar[2]='☂ '
fi
stashes=$(git stash list 2>/dev/null | wc -l)
if [ ${stashes} -eq 0 ]
then
psvar[3]+=""
else
psvar[3]+="@${stashes// /}"
fi
fi
if [ $is_fine == 1 ]
then
RPROMPT=%B"%1(v|%F{magenta}%1v%f%F{red}%2v%f%F{yellow}%3v%f|)"%b${_DIRPART}
else
RPROMPT=%B"%1(v|%F{magenta}%1v%f%F{cyan}%2v%f%F{yellow}%3v%f|)"%b${_DIRPART}
fi
}
_DIRPART=%B%{$fg[green]%}'[%(5~,%-2~/.../%2~,%~)]'%{$reset_color%}%b
RPROMPT=%B"%1(v|%F{magenta}%1v%f%2v%f%F{yellow}%3v%f|)"%b${_DIRPART}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment