From 59ef2a610664c2891f7a9a81751d4e195d3337ab Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 22 Mar 2015 17:36:54 +0100 Subject: [PATCH 1/5] First part: added Mercurial support. --- powerlevel9k.zsh-theme | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 21bb9b40..4a3ceac9 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -33,12 +33,12 @@ RIGHT_SEGMENT_SEPARATOR='' setopt prompt_subst autoload -Uz vcs_info zstyle ':vcs_info:*' stagedstr " %F{black}✚%f" -zstyle ':vcs_info:git:*' unstagedstr " %F{black}●%f" -zstyle ':vcs_info:git*' actionformats " %b %F{red}| %a%f" -zstyle ':vcs_info:git*' formats " %b%c%u%m" +zstyle ':vcs_info:*' unstagedstr " %F{black}●%f" +zstyle ':vcs_info:*' actionformats " %b %F{red}| %a%f" +zstyle ':vcs_info:*' formats " %b%c%u%m" zstyle ':vcs_info:*' check-for-changes true zstyle ':vcs_info:git*+set-message:*' hooks git-untracked git-aheadbehind git-remotebranch git-tagname -zstyle ':vcs_info:*' enable git +zstyle ':vcs_info:*' enable git hg ################################################################ # Prompt Segment Constructors From ba2ab6ec4a71b4df3dad39e81259490eea0bfa0a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 22 Mar 2015 22:45:55 +0100 Subject: [PATCH 2/5] Added mercurial support. --- powerlevel9k.zsh-theme | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index a88827ee..7edc05ea 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -25,6 +25,8 @@ CURRENT_BG='NONE' # bizarre characters below, your fonts are not correctly installed. LEFT_SEGMENT_SEPARATOR='' RIGHT_SEGMENT_SEPARATOR='' +VCS_UNSTAGED_ICON='●' +VCS_STAGED_ICON='✚' ################################################################ # vcs_info settings for git @@ -32,12 +34,14 @@ RIGHT_SEGMENT_SEPARATOR='' setopt prompt_subst autoload -Uz vcs_info -zstyle ':vcs_info:*' stagedstr " %F{black}✚%f" -zstyle ':vcs_info:*' unstagedstr " %F{black}●%f" +zstyle ':vcs_info:*' stagedstr " %F{black}$VCS_STAGED_ICON%f" +zstyle ':vcs_info:*' unstagedstr " %F{black}$VCS_UNSTAGED_ICON%f" zstyle ':vcs_info:*' actionformats " %b %F{red}| %a%f" zstyle ':vcs_info:*' formats " %b%c%u%m" zstyle ':vcs_info:*' check-for-changes true zstyle ':vcs_info:git*+set-message:*' hooks git-untracked git-aheadbehind git-remotebranch git-tagname +zstyle ':vcs_info:hg*' get-revision true # If false, the dirty-check won't work in mercurial +zstyle ':vcs_info:hg*:*' branchformat "%b" # only show branch zstyle ':vcs_info:*' enable git hg ################################################################ @@ -96,18 +100,24 @@ prompt_context() { } # Git: branch/detached head, dirty status -prompt_git() { - local dirty +prompt_vcs() { + local dirty=false + local vcs_prompt="${vcs_info_msg_0_}" - if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then - dirty=$(parse_git_dirty) - if [[ -n $dirty ]]; then + 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 $1_prompt_segment yellow black else $1_prompt_segment green black fi - echo -n "${vcs_info_msg_0_}" + echo -n "$vcs_prompt" fi } @@ -230,7 +240,7 @@ prompt_rvm() { # Main prompt build_left_prompt() { if (( ${#POWERLEVEL9K_LEFT_PROMPT_ELEMENTS} == 0 )); then - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir git) + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs) fi for element in $POWERLEVEL9K_LEFT_PROMPT_ELEMENTS; do From dbcf3f74794282d6e652830af6cefd5110f70b9d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 29 Mar 2015 18:06:57 +0200 Subject: [PATCH 3/5] 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 7edc05ea..ebc77fc9 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%}' From f1518de92fd58f437fbb9fe37ca30452b2207125 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 29 Mar 2015 18:09:27 +0200 Subject: [PATCH 4/5] Debugging comment added. --- powerlevel9k.zsh-theme | 3 +++ 1 file changed, 3 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index ebc77fc9..00271a08 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -45,6 +45,9 @@ zstyle ':vcs_info:hg*' get-revision true # If false, the dirty-check won't work zstyle ':vcs_info:hg*:*' branchformat "%b" # only show branch zstyle ':vcs_info:*' enable git hg +## Debugging +#zstyle ':vcs_info:*+*:*' debug true + ################################################################ # Prompt Segment Constructors ################################################################ From 1f3c8e4d775dccb353d56a7bad3da4b99ca51707 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 29 Mar 2015 18:26:02 +0200 Subject: [PATCH 5/5] Bugfix: we have to reset the dirty-state once we visited a dirty working copy. And a bit of formatting. --- powerlevel9k.zsh-theme | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 00271a08..4a6f5655 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -103,7 +103,7 @@ prompt_context() { fi } -# Git: branch/detached head, dirty status +# branch/detached head, dirty status prompt_vcs() { local vcs_prompt="${vcs_info_msg_0_}" @@ -168,9 +168,11 @@ function +vi-git-tagname() { } function +vi-vcs-detect-changes() { - if [[ -n ${hook_com[staged]} ]] || [[ -n ${hook_com[unstaged]} ]]; then - VCS_WORKDIR_DIRTY=true - fi + if [[ -n ${hook_com[staged]} ]] || [[ -n ${hook_com[unstaged]} ]]; then + VCS_WORKDIR_DIRTY=true + else + VCS_WORKDIR_DIRTY=false + fi } # Dir: current working directory @@ -268,9 +270,9 @@ build_right_prompt() { # Create the prompts precmd() { - vcs_info - # Add a static hook to examine staged/unstaged changes. - vcs_info_hookadd set-message vcs-detect-changes + 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) '