autoload -Uz vcs_info # only look for certain VCS zstyle ':vcs_info:*' enable git # check repository for changes so that they can be used in %u/%c # (this might be slow for bigger repositories) zstyle ':vcs_info:*' check-for-changes yes # display current branch (%b -> green), unstaged + staged changes (%u/%c -> green), # VCS (%s -> blue) and custom messages (%m). zstyle ':vcs_info:*' formats \ "%F{green}%b%u%c%F{default}:%F{blue}%s%F{default}%m" # during special actions (e.g. merge, rebase), also display those (%a -> red) zstyle ':vcs_info:*' actionformats \ "(%F{green}%b%u%c%F{default}/%F{red}%a%F{default}:%F{blue}%s%F{default}%m)" # set style for formats/actionformats when unstaged (%u) and staged (%c) # changes are detected in the repository # (check-for-changes must be true for this to work) zstyle ':vcs_info:*' unstagedstr '¹' zstyle ':vcs_info:*' stagedstr '²' # force vcs_info to be run. this prevents running it later for performance reasons. # default to run vcs_info. will be prevented from running later if possible # (for speedup) zshrc_force_run_vcs_info=1 # cache data zstyle ':vcs_info:*+pre-get-data:*' hooks pre-get-data +vi-pre-get-data() { # only git and mercurial support and need caching. ignore all other VCS [[ $vcs != git && $vcs != hg ]] && return # run vcs_info on startup, on directory change (or for other custom reasons) 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 case $(fc -ln $(($HISTCMD-1))) in # vcs status might need an update after running git/hg git* | g\ *) ret=0 ;; esac } # display stash count function +vi-git-stashes() { if [[ -s ${hook_com[base]/.git/refs/stash} ]]; then local -a stashes # "grep" output of git stash list via (M) and :#(...) stashes=( ${(M)${(f)"$(git stash list 2>/dev/null)"}:#(*WIP*)} ) if [[ ${#stashes} -gt 0 ]]; then hook_com[misc]+=" %F{yellow}${#stashes}s%F{default}" fi fi } zstyle ':vcs_info:git*+set-message:*' hooks git-stashes # enforce running vcs_info when changing directory prompt_chpwd() { zshrc_force_run_vcs_info=1 } chpwd_functions+=(prompt_chpwd)