diff options
author | Adam Lindberg <hello@alind.io> | 2014-04-16 10:34:45 +0200 |
---|---|---|
committer | ncanceill <nicolas.canceill@ens-cachan.org> | 2015-06-10 14:36:55 +0200 |
commit | 2d40cc0bb315a92368e35c15c92f955bd901c7c3 (patch) | |
tree | d3223d0c72ce169d8a4b4dc96139439e83b627d4 /lib/git.zsh | |
parent | f21a672fed1e1455c8341c972f3ba5a408726053 (diff) | |
download | zsh-2d40cc0bb315a92368e35c15c92f955bd901c7c3.tar.gz zsh-2d40cc0bb315a92368e35c15c92f955bd901c7c3.tar.bz2 zsh-2d40cc0bb315a92368e35c15c92f955bd901c7c3.zip |
Add git_prompt_behind and git_prompt_exists
This adds two new theme functions for git:
* `git_prompt_behind` works in a identical fashion to `git_prompt_ahead`
and will output a format variable (`ZSH_THEME_GIT_PROMPT_BEHIND`) if
the branch is behind.
* `git_prompt_remote` will output one format variable if the branch
exists on remote (`ZSH_THEME_GIT_PROMPT_REMOTE_EXISTS`), and another
if the branch is unpublished (`ZSH_THEME_GIT_PROMPT_REMOTE_MISSING`).
The old `git_prompt_ahead` has been changed. Using git log is subject
to formatting in .gitconfig, which can be overridden and will break
this function. Relying on rev-list is much more stable.
Diffstat (limited to 'lib/git.zsh')
-rw-r--r-- | lib/git.zsh | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/lib/git.zsh b/lib/git.zsh index 733492ba0..caa7e6329 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -59,13 +59,6 @@ git_remote_status() { fi } -# Checks if there are commits ahead from remote -function git_prompt_ahead() { - if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then - echo "$ZSH_THEME_GIT_PROMPT_AHEAD" - fi -} - # Gets the number of commits ahead from remote function git_commits_ahead() { if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then @@ -74,6 +67,29 @@ function git_commits_ahead() { fi } +# Outputs if current branch is ahead of remote +function git_prompt_ahead() { + if [[ -n "$(command git rev-list origin/$(current_branch)..HEAD 2> /dev/null)" ]]; then + echo "$ZSH_THEME_GIT_PROMPT_AHEAD" + fi +} + +# Outputs if current branch is behind remote +function git_prompt_behind() { + if [[ -n "$(command git rev-list HEAD..origin/$(current_branch) 2> /dev/null)" ]]; then + echo "$ZSH_THEME_GIT_PROMPT_BEHIND" + fi +} + +# Outputs if current branch exists on remote or not +function git_prompt_remote() { + if [[ -n "$(command git show-ref origin/$(current_branch) 2> /dev/null)" ]]; then + echo "$ZSH_THEME_GIT_PROMPT_REMOTE_EXISTS" + else + echo "$ZSH_THEME_GIT_PROMPT_REMOTE_MISSING" + fi +} + # Formats prompt string for current git commit short SHA function git_prompt_short_sha() { SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" |