Modified lib/zsh.sh for better prefix/suffix support

This commit is contained in:
Nuno Cardoso 2012-07-01 14:13:13 +01:00
commit b643d50f5f
2 changed files with 9 additions and 6 deletions

View file

@ -1,7 +1,12 @@
# get the name of the branch we are on
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"
if parse_git_dirty; then
INFO="$ZSH_THEME_GIT_PROMPT_DIRTY_PREFIX${ref#refs/heads/}$ZSH_THEME_GIT_PROMPT_DIRTY"
else
INFO="$ZSH_THEME_GIT_PROMPT_CLEAN_PREFIX${ref#refs/heads/}$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
echo "$ZSH_THEME_GIT_PROMPT_PREFIX$INFO$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
@ -11,11 +16,7 @@ parse_git_dirty() {
if [[ $POST_1_7_2_GIT -gt 0 ]]; then
SUBMODULE_SYNTAX="--ignore-submodules=dirty"
fi
if [[ -n $(git status -s ${SUBMODULE_SYNTAX} 2> /dev/null) ]]; then
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
else
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
[[ -n $(git status -s ${SUBMODULE_SYNTAX} 2> /dev/null) ]] && return 0 || return 1
}

View file

@ -28,7 +28,9 @@ PS1="%n@%m:%~%# "
# git theming default: Variables for theming the git info prompt
ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of the prompt, before the branch name
ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt
ZSH_THEME_GIT_PROMPT_DIRTY_PREFIX="" # Text to display if the branch is dirty
ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty
ZSH_THEME_GIT_PROMPT_CLEAN_PREFIX="" # Text to display if the branch is clean
ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean
# Setup the prompt with pretty colors