From 16621f2ce5ffddda2e40699ee84d20811bcb803a Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Sun, 25 Jan 2015 20:52:25 -0800 Subject: [PATCH] powerlevel-9k zsh theme: incorporting tupton's vcs_info suggestions --- powerlevel9k.zsh-theme | 86 +++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 23 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d7f0e34..3211452 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -10,6 +10,16 @@ # [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts). # +setopt prompt_subst +autoload -Uz vcs_info +zstyle ':vcs_info:*' stagedstr '✚' +zstyle ':vcs_info:git:*' unstagedstr '●' +zstyle ':vcs_info:git*' actionformats " %b %F{red}| %a%f" +zstyle ':vcs_info:git*' 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 + ### Segment drawing # A few utility functions to make it easy and re-usable to draw segmented prompts @@ -80,41 +90,69 @@ prompt_context() { # Git: branch/detached head, dirty status prompt_git() { - local ref dirty mode repo_path - repo_path=$(git rev-parse --git-dir 2>/dev/null) + local dirty if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then dirty=$(parse_git_dirty) - ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)" if [[ -n $dirty ]]; then left_prompt_segment yellow black else left_prompt_segment green black fi - if [[ -e "${repo_path}/BISECT_LOG" ]]; then - mode=" " - elif [[ -e "${repo_path}/MERGE_HEAD" ]]; then - mode=" >M<" - elif [[ -e "${repo_path}/rebase" || -e "${repo_path}/rebase-apply" || -e "${repo_path}/rebase-merge" || -e "${repo_path}/../.dotest" ]]; then - mode=" >R>" - fi - - setopt promptsubst - autoload -Uz vcs_info - - zstyle ':vcs_info:*' enable git - zstyle ':vcs_info:*' get-revision true - zstyle ':vcs_info:*' check-for-changes true - zstyle ':vcs_info:*' stagedstr '✚' - zstyle ':vcs_info:git:*' unstagedstr '●' - zstyle ':vcs_info:*' formats ' %u%c' - zstyle ':vcs_info:*' actionformats ' %u%c' - vcs_info - echo -n "${ref/refs\/heads\// }${vcs_info_msg_0_%% }${mode}" + echo -n "${vcs_info_msg_0_}" fi } +function +vi-git-untracked() { + if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \ + $(git ls-files --others --exclude-standard | sed q | wc -l | tr -d ' ') != 0 ]]; then + hook_com[unstaged]+="%F{black}?%f" + fi +} + +function +vi-git-aheadbehind() { + local ahead behind branch_name + local -a gitstatus + + branch_name=${$(git symbolic-ref --short HEAD 2>/dev/null)} + + # for git prior to 1.7 + # ahead=$(git rev-list origin/${branch_name}..HEAD | wc -l) + ahead=$(git rev-list ${branch_name}@{upstream}..HEAD 2>/dev/null | wc -l | tr -d ' ') + (( $ahead )) && gitstatus+=( "%F{black}↑${ahead}%f" ) + + # for git prior to 1.7 + # behind=$(git rev-list HEAD..origin/${branch_name} | wc -l) + behind=$(git rev-list HEAD..${branch_name}@{upstream} 2>/dev/null | wc -l | tr -d ' ') + (( $behind )) && gitstatus+=( "%F{black}↓${behind}%f" ) + + hook_com[misc]+=${(j::)gitstatus} +} + +function +vi-git-remotebranch() { + local remote branch_name + + # Are we on a remote-tracking branch? + remote=${$(git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)/refs\/(remotes|heads)\/} + branch_name=${$(git symbolic-ref --short HEAD 2>/dev/null)} + + hook_com[branch]="%F{black}${hook_com[branch]}%f" + # Always show the remote + #if [[ -n ${remote} ]] ; then + # Only show the remote if it differs from the local + if [[ -n ${remote} && ${remote#*/} != ${branch_name} ]] ; then + hook_com[branch]+="%F{black}→%f%F{black}${remote}%f" + fi +} + +function +vi-git-tagname() { + local tag + + tag=$(git describe --tags --exact-match HEAD 2>/dev/null) + [[ -n ${tag} ]] && hook_com[branch]="%F{black}${tag}%f" +} + # Mercurial status prompt_hg() { local rev status @@ -238,5 +276,7 @@ build_right_prompt() { } # Create the prompts +precmd() { vcs_info } + PROMPT='%{%f%b%k%}$(build_left_prompt) ' RPROMPT='%{%f%b%k%}$(build_right_prompt)%{$reset_color%}'