From b643d50f5f4be0ac5e7d4fb5d1b78e0ce058aa1e Mon Sep 17 00:00:00 2001 From: Nuno Cardoso Date: Sun, 1 Jul 2012 14:13:13 +0100 Subject: [PATCH] Modified lib/zsh.sh for better prefix/suffix support --- lib/git.zsh | 13 +++++++------ lib/theme-and-appearance.zsh | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/git.zsh b/lib/git.zsh index fb4ad8ca6..2ac79834f 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -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 } diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index aec67721a..80830e3be 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -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