Skip to content

Commit

Permalink
Add branch status support to git_prompt_status
Browse files Browse the repository at this point in the history
This patch makes git_prompt_status support three new status variables:

 - ZSH_THEME_GIT_PROMPT_AHEAD
 - ZSH_THEME_GIT_PROMPT_BEHIND
 - ZSH_THEME_GIT_PROMPT_DIVERGED

With these extra variables it's easy to see (1) if you have commits in
your local branch that weren't pushed to the remote (AHEAD), (2) if
there are commits in the remote that you haven't merged/rebased yet
(BEHIND) or (3) if you have local unpushed commits AND the remote has
some commits you haven't merged yet (DIVERGED).

Refer to the first line displayed on `git status -b --porcelain`.

An example setup in a .zsh-theme file would be:

ZSH_THEME_GIT_PROMPT_AHEAD="↑"
ZSH_THEME_GIT_PROMPT_BEHIND="↓"
ZSH_THEME_GIT_PROMPT_DIVERGED="↕"
  • Loading branch information
caio committed Jul 29, 2012
1 parent d05b201 commit a3c2a2f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/git.zsh
Expand Up @@ -38,7 +38,7 @@ function git_prompt_long_sha() {

# Get the status of the working tree
git_prompt_status() {
INDEX=$(git status --porcelain 2> /dev/null)
INDEX=$(git status --porcelain -b 2> /dev/null)
STATUS=""
if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
Expand Down Expand Up @@ -66,6 +66,15 @@ git_prompt_status() {
if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
fi
if $(echo "$INDEX" | grep '^## .*ahead' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS"
fi
if $(echo "$INDEX" | grep '^## .*behind' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS"
fi
if $(echo "$INDEX" | grep '^## .*diverged' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS"
fi
echo $STATUS
}

Expand Down

0 comments on commit a3c2a2f

Please sign in to comment.