From fcb9a783ed34476256ad253f55e7ab7305d0e535 Mon Sep 17 00:00:00 2001 From: Felix Mauch Date: Fri, 27 May 2016 14:42:18 +0200 Subject: [PATCH] show ahead and behind numbers on git prompt --- themes/bureau.zsh-theme | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/themes/bureau.zsh-theme b/themes/bureau.zsh-theme index 3b3bdc80f..6d77b9f97 100644 --- a/themes/bureau.zsh-theme +++ b/themes/bureau.zsh-theme @@ -10,8 +10,10 @@ ZSH_THEME_NVM_PROMPT_SUFFIX="" ZSH_THEME_GIT_PROMPT_PREFIX="[%{$fg_bold[green]%}±%{$reset_color%}%{$fg_bold[white]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}]" ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}✓%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg[cyan]%}▴%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg[magenta]%}▾%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_AHEAD="▴" +ZSH_THEME_GIT_PROMPT_AHEAD_COLOR="cyan" +ZSH_THEME_GIT_PROMPT_BEHIND="▾" +ZSH_THEME_GIT_PROMPT_BEHIND_COLOR="magenta" ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}" ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}●%{$reset_color%}" ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}" @@ -46,11 +48,14 @@ bureau_git_status() { # check status of local repository _INDEX=$(command git status --porcelain -b 2> /dev/null) - if $(echo "$_INDEX" | command grep -q '^## .*ahead'); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD" + _AHEAD_BEHIND=$(echo $_INDEX | grep '^## .*[ahead|behind] \[*[0-9]\+*\]' | sed 's/.*\[\([^]]*\)\].*/\1/g') + if $(echo "$_AHEAD_BEHIND" | command grep -q 'ahead'); then + num=$(echo "$_AHEAD_BEHIND" | command sed 's/.*ahead \([0-9]*\).*/\1/') + _STATUS="$_STATUS%{$fg[$ZSH_THEME_GIT_PROMPT_AHEAD_COLOR]%}$ZSH_THEME_GIT_PROMPT_AHEAD$num%{$reset_color%}" fi - if $(echo "$_INDEX" | command grep -q '^## .*behind'); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND" + if $(echo "$_INDEX" | command grep -q '^## .*behind [0-9]*'); then + num=$(echo "$_AHEAD_BEHIND" | command sed 's/.*behind \([0-9]*\).*/\1/') + _STATUS="$_STATUS%{$fg[$ZSH_THEME_GIT_PROMPT_BEHIND_COLOR]%}$ZSH_THEME_GIT_PROMPT_BEHIND$num%{$reset_color%}" fi if $(echo "$_INDEX" | command grep -q '^## .*diverged'); then _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED"