- # it's also displayed (red).
- zstyle ':vcs_info:*' formats \
- "(%{${fg[green]}%}%b%{${fg[default]}%}:\
-%{${fg[blue]}%}%s%{${fg[default]}%})"
- zstyle ':vcs_info:*' actionformats \
- "(%{${fg[green]}%}%b%{${fg[default]}%}/\
-%{${fg[red]}%}%a%{${fg[default]}%}:\
-%{${fg[blue]}%}%s%{${fg[default]}%})"
- # Call vcs_info as precmd before every prompt.
- prompt_precmd() {
- vcs_info
+ # it's also displayed (red). Also display if there are unstaged or staged
+ # (%u/%c) changes.
+ 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}%m)" \
+ "${green}%u%c${default}"
+ zstyle ':vcs_info:*' actionformats \
+ "(${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
+ # correctly expanded.
+ zstyle ':vcs_info:*' formats \
+ "(${green}%b${default}:${blue}%s${default})"
+ zstyle ':vcs_info:*' actionformats \
+ "(${green}%b${default}/${red}%a${default}:${blue}%s${default})"
+ fi
+ # Set style for formats/actionformats when unstaged (%u) and staged (%c)
+ # changes are detected in the repository; check-for-changes must be set to
+ # true for this to work. Thanks to Bart Trojanowski
+ # (http://jukie.net/~bart/blog/pimping-out-zsh-prompt) for the idea
+ # (2010-03-11 00:20 CET).
+ zstyle ':vcs_info:*' unstagedstr '¹'
+ zstyle ':vcs_info:*' stagedstr '²'
+
+ # Default to run vcs_info. If possible we prevent running it later for
+ # speed reasons. If set to a non empty value vcs_info is run.
+ zshrc_force_run_vcs_info=1
+
+ # Cache system inspired by Bart Trojanowski
+ # (http://jukie.net/~bart/blog/pimping-out-zsh-prompt).
+ zstyle ':vcs_info:*+pre-get-data:*' hooks pre-get-data
+ +vi-pre-get-data() {
+ # Only Git and Mercurial support and need caching. Abort if any other
+ # VCS is used.
+ [[ "$vcs" != git && "$vcs" != hg ]] && return
+
+ # If the shell just started up or we changed directories (or for other
+ # custom reasons) we must run vcs_info.
+ if [[ -n $zshrc_force_run_vcs_info ]]; then
+ zshrc_force_run_vcs_info=
+ return
+ fi
+
+ # Don't run vcs_info by default to speed up the shell.
+ ret=1
+ # If a git/hg command was run then run vcs_info as the status might
+ # need to be updated.
+ case "$(fc -ln $(($HISTCMD-1)))" in
+ git* | g\ *)
+ ret=0
+ ;;
+ hg*)
+ ret=0
+ ;;
+ 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