Use a vcs library and add a Mercurial plugin

Move git_* functions to vcs_* to allow for better plugin support
Modify plugins to use the new function names and declare new variable
names, so ZSH_THEME_GIT_* variables are ZSH_THEME_VCS_* and
git_prompt_info() is vcs_prompt_info()
This commit is contained in:
Jared Hancock 2011-04-07 22:59:01 -05:00
commit 753646e458
64 changed files with 370 additions and 295 deletions

View file

@ -1,14 +1,22 @@
# get the name of the branch we are on
VCS+="git"
function git_check() {
git status -s > /dev/null 2>&1
return $?
}
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
echo "${(e)ZSH_THEME_VCS_PROMPT_PREFIX}${ref#refs/heads/}$(parse_git_dirty)${ZSH_THEME_VCS_PROMPT_SUFFIX}"
}
parse_git_dirty () {
if [[ -n $(git status -s 2> /dev/null) ]]; then
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
echo "$ZSH_THEME_VCS_PROMPT_DIRTY"
else
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
echo "$ZSH_THEME_VCS_PROMPT_CLEAN"
fi
}
@ -17,28 +25,28 @@ git_prompt_status() {
INDEX=$(git status --porcelain 2> /dev/null)
STATUS=""
if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
STATUS="$ZSH_THEME_VCS_PROMPT_UNTRACKED$STATUS"
fi
if $(echo "$INDEX" | grep '^A ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
STATUS="$ZSH_THEME_VCS_PROMPT_ADDED$STATUS"
elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
STATUS="$ZSH_THEME_VCS_PROMPT_ADDED$STATUS"
fi
if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
STATUS="$ZSH_THEME_VCS_PROMPT_MODIFIED$STATUS"
elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
STATUS="$ZSH_THEME_VCS_PROMPT_MODIFIED$STATUS"
elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
STATUS="$ZSH_THEME_VCS_PROMPT_MODIFIED$STATUS"
fi
if $(echo "$INDEX" | grep '^R ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS"
STATUS="$ZSH_THEME_VCS_PROMPT_RENAMED$STATUS"
fi
if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
STATUS="$ZSH_THEME_VCS_PROMPT_DELETED$STATUS"
fi
if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
STATUS="$ZSH_THEME_VCS_PROMPT_UNMERGED$STATUS"
fi
echo $STATUS
}

26
lib/vcs.zsh Normal file
View file

@ -0,0 +1,26 @@
function vcs_name() {
for vcs in $VCS; do
if ${vcs}_check; then
echo $vcs
break
fi
done
}
# get the name of the branch we are on
function vcs_prompt_info() {
local vcs=$(vcs_name)
[[ -n $vcs ]] && ${vcs}_prompt_info
}
function parse_vcs_dirty () {
local vcs=$(vcs_name)
[[ -n $vcs ]] && parse_${vcs}_dirty
}
# get the status of the working tree
function vcs_prompt_status() {
local vcs=$(vcs_name)
[[ -n $vcs ]] && ${vcs}_prompt_status
}