summaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorBen Hilburn <bhilburn@gmail.com>2015-01-26 07:52:25 +0300
committerBen Hilburn <bhilburn@gmail.com>2015-01-29 07:59:23 +0300
commit16621f2ce5ffddda2e40699ee84d20811bcb803a (patch)
tree453904af934d9c855ef912251e597605de6a7de6 /powerlevel9k.zsh-theme
parent5943ef20ad529350fe081b6f92f7e44bd2bbd867 (diff)
powerlevel-9k zsh theme: incorporting tupton's vcs_info suggestions
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rw-r--r--powerlevel9k.zsh-theme84
1 files changed, 62 insertions, 22 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index d7f0e34d..32114523 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,39 +90,67 @@ 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=" <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>"
+ 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
+}
- 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}"
- 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
@@ -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%}'