]> ruderich.org/simon Gitweb - config/dotfiles.git/commitdiff
zsh/rc: Display number of Git stashes in prompt.
authorSimon Ruderich <simon@ruderich.org>
Sat, 6 Jul 2013 14:56:02 +0000 (16:56 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sat, 6 Jul 2013 14:56:02 +0000 (16:56 +0200)
zsh/rc

diff --git a/zsh/rc b/zsh/rc
index c6691783224feb182fc95edfc7f521d98fbad12b..48f12fc4b0b0b70fc7866d03d6c1f4661889d0ed 100644 (file)
--- a/zsh/rc
+++ b/zsh/rc
@@ -234,10 +234,10 @@ if [[ $ZSH_VERSION == (4.3.<9->*|4.<4->*|<5->*) ||
     if [[ $ZSH_VERSION == (4.3.<11->*|4.<4->*|<5->*) ||
           -d ~/.zsh/functions/vcs_info ]]; then
         zstyle ':vcs_info:*' formats \
-            "(${green}%b%u%c${default}:${blue}%s${default})" \
+            "(${green}%b%u%c${default}:${blue}%s${default}%m)" \
             "${green}%u%c${default}"
         zstyle ':vcs_info:*' actionformats \
-            "(${green}%b%u%c${default}/${red}%a${default}:${blue}%s${default})" \
+            "(${green}%b%u%c${default}/${red}%a${default}:${blue}%s${default}%m)" \
             "${green}%u%c${default}"
     else
         # In older versions %u and %c are not defined yet and are not
@@ -288,6 +288,26 @@ if [[ $ZSH_VERSION == (4.3.<9->*|4.<4->*|<5->*) ||
         esac
     }
 
+    # Display number of WIP stashes (this excludes manually named commits
+    # which might be used for something else), thanks to
+    # http://eseth.org/2010/git-in-zsh.html (viewed on 2013-04-27) for the
+    # idea to display the stash count.
+    function +vi-git-stashes() {
+        if [[ -s ${hook_com[base]/.git/refs/stash} ]]; then
+            local -a stashes
+            # Thanks to Valodim in #zsh on Freenode (2013-07-01 14:14 CEST)
+            # for the solution to "grep" the output with (M) and :#(...).
+            stashes=${#${(M)${(f)"$(git stash list 2>/dev/null)"}:#(*WIP*)}}
+
+            if [[ $stashes -gt 0 ]]; then
+                hook_com[misc]+=" ${yellow}${stashes}s${default}"
+            fi
+        fi
+    }
+
+    # Apply hooks to Git.
+    zstyle ':vcs_info:git*+set-message:*' hooks git-stashes
+
     # Must run vcs_info when changing directories.
     prompt_chpwd() {
         zshrc_force_run_vcs_info=1