From 303fb7286ca5151d5454d435a193024650d3bdf2 Mon Sep 17 00:00:00 2001 From: Jan Gosmann Date: Sat, 25 Feb 2012 22:43:40 +0100 Subject: [PATCH] More detailed git prompt information. Possibility to also display if a branch is behind, has diverged or is up-to-date. Also changed the implementation to use git-rev-list which is a bit easier than git-log. --- lib/git.zsh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/git.zsh b/lib/git.zsh index 534c1072c..844a31d16 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -22,8 +22,16 @@ parse_git_dirty() { # Checks if there are commits ahead from remote function git_prompt_ahead() { - if $(echo "$(git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then - echo "$ZSH_THEME_GIT_PROMPT_AHEAD" + ahead=$(git rev-list origin/$(current_branch)..HEAD -- 2> /dev/null) + behind=$(git rev-list HEAD..origin/$(current_branch) -- 2> /dev/null) + if [[ -n $ahead && -n $behind ]]; then + echo "$ZSH_THEME_GIT_PROMPT_DIVERGED" + elif [[ -n $ahead ]]; then + echo "$ZSH_THEME_GIT_PROMPT_AHEAD" + elif [[ -n $behind ]]; then + echo "$ZSH_THEME_GIT_PROMPT_BEHIND" + else + echo "$ZSH_THEME_GIT_PROMPT_UPTODATE" fi }