From dbcf3f74794282d6e652830af6cefd5110f70b9d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 29 Mar 2015 18:06:57 +0200 Subject: [PATCH] A better approach to detect the dirty status of our working copy. --- powerlevel9k.zsh-theme | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7edc05e..ebc77fc 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -32,6 +32,7 @@ VCS_STAGED_ICON='✚' # vcs_info settings for git ################################################################ +local VCS_WORKDIR_DIRTY=false setopt prompt_subst autoload -Uz vcs_info zstyle ':vcs_info:*' stagedstr " %F{black}$VCS_STAGED_ICON%f" @@ -101,17 +102,10 @@ prompt_context() { # Git: branch/detached head, dirty status prompt_vcs() { - local dirty=false local vcs_prompt="${vcs_info_msg_0_}" if [[ -n $vcs_prompt ]]; then - if [[ $vcs_prompt =~ $VCS_UNSTAGED_ICON ]]; then - dirty=true - elif [[ $vcs_prompt =~ $VCS_STAGED_ICON ]]; then - dirty=true - fi - - if ( $dirty ); then + if ( $VCS_WORKDIR_DIRTY ); then $1_prompt_segment yellow black else $1_prompt_segment green black @@ -170,6 +164,12 @@ function +vi-git-tagname() { [[ -n ${tag} ]] && hook_com[branch]=" %F{black}${tag}%f" } +function +vi-vcs-detect-changes() { + if [[ -n ${hook_com[staged]} ]] || [[ -n ${hook_com[unstaged]} ]]; then + VCS_WORKDIR_DIRTY=true + fi +} + # Dir: current working directory prompt_dir() { $1_prompt_segment blue black '%~' @@ -264,7 +264,11 @@ build_right_prompt() { } # Create the prompts -precmd() { vcs_info } +precmd() { + vcs_info + # Add a static hook to examine staged/unstaged changes. + vcs_info_hookadd set-message vcs-detect-changes +} PROMPT='%{%f%b%k%}$(build_left_prompt) ' RPROMPT='%{%f%b%k%}$(build_right_prompt)%{$reset_color%}'