powerlevel-9k zsh theme: incorporting tupton's vcs_info suggestions

pull/22/head
Ben Hilburn 10 years ago
parent 5943ef20ad
commit 16621f2ce5

@ -10,6 +10,16 @@
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts). # [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 ### Segment drawing
# A few utility functions to make it easy and re-usable to draw segmented prompts # 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 # Git: branch/detached head, dirty status
prompt_git() { prompt_git() {
local ref dirty mode repo_path local dirty
repo_path=$(git rev-parse --git-dir 2>/dev/null)
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
dirty=$(parse_git_dirty) 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 if [[ -n $dirty ]]; then
left_prompt_segment yellow black left_prompt_segment yellow black
else else
left_prompt_segment green black left_prompt_segment green black
fi fi
if [[ -e "${repo_path}/BISECT_LOG" ]]; then echo -n "${vcs_info_msg_0_}"
mode=" <B>"
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 fi
}
setopt promptsubst function +vi-git-untracked() {
autoload -Uz vcs_info 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
}
zstyle ':vcs_info:*' enable git function +vi-git-aheadbehind() {
zstyle ':vcs_info:*' get-revision true local ahead behind branch_name
zstyle ':vcs_info:*' check-for-changes true local -a gitstatus
zstyle ':vcs_info:*' stagedstr '✚'
zstyle ':vcs_info:git:*' unstagedstr '●' branch_name=${$(git symbolic-ref --short HEAD 2>/dev/null)}
zstyle ':vcs_info:*' formats ' %u%c'
zstyle ':vcs_info:*' actionformats ' %u%c' # for git prior to 1.7
vcs_info # ahead=$(git rev-list origin/${branch_name}..HEAD | wc -l)
echo -n "${ref/refs\/heads\// }${vcs_info_msg_0_%% }${mode}" 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 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 # Mercurial status
prompt_hg() { prompt_hg() {
local rev status local rev status
@ -238,5 +276,7 @@ build_right_prompt() {
} }
# Create the prompts # Create the prompts
precmd() { vcs_info }
PROMPT='%{%f%b%k%}$(build_left_prompt) ' PROMPT='%{%f%b%k%}$(build_left_prompt) '
RPROMPT='%{%f%b%k%}$(build_right_prompt)%{$reset_color%}' RPROMPT='%{%f%b%k%}$(build_right_prompt)%{$reset_color%}'

Loading…
Cancel
Save