From e7449e94c9941a8c1235c8b5cd495c2700e77abe Mon Sep 17 00:00:00 2001 From: mafro Date: Fri, 3 Oct 2014 17:07:40 +1000 Subject: [PATCH] Add git-info diverged subcontext for prompt formatting --- modules/git/README.md | 1 + modules/git/functions/git-info | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/git/README.md b/modules/git/README.md index 0dd932f6..33941e39 100644 --- a/modules/git/README.md +++ b/modules/git/README.md @@ -254,6 +254,7 @@ setting a style is as follows. | action | %s | Special action name | ahead | %A | Commits ahead of remote count | behind | %B | Commits behind of remote count +| diverged | %V | Diverged from remote state | branch | %b | Branch name | commit | %c | Commit hash | position | %p | Commits from the nearest tag count diff --git a/modules/git/functions/git-info b/modules/git/functions/git-info index bc627240..67129d0d 100644 --- a/modules/git/functions/git-info +++ b/modules/git/functions/git-info @@ -125,6 +125,8 @@ function git-info { local dirty=0 local dirty_format local dirty_formatted + local diverged + local diverged_formatted local ignore_submodules local indexed=0 local indexed_format @@ -252,9 +254,14 @@ function git-info { # Get ahead and behind counts. ahead_and_behind="$(${(z)ahead_and_behind_cmd} 2> /dev/null)" + ahead="$ahead_and_behind[(w)1]" + behind="$ahead_and_behind[(w)2]" + if (( ahead > 0 )) && (( behind > 0 )); then + zstyle -s ':prezto:module:git:info:diverged' format 'diverged_formatted' + fi + # Format ahead. if [[ -n "$ahead_format" ]]; then - ahead="$ahead_and_behind[(w)1]" if (( ahead > 0 )); then zformat -f ahead_formatted "$ahead_format" "A:$ahead" fi @@ -262,7 +269,6 @@ function git-info { # Format behind. if [[ -n "$behind_format" ]]; then - behind="$ahead_and_behind[(w)2]" if (( behind > 0 )); then zformat -f behind_formatted "$behind_format" "B:$behind" fi @@ -411,7 +417,8 @@ function git-info { "s:$action_formatted" \ "S:$stashed_formatted" \ "U:$unmerged_formatted" \ - "u:$untracked_formatted" + "u:$untracked_formatted" \ + "V:$diverged_formatted" git_info[$info_format]="$REPLY" done