summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorLennart Ochel <lennart.ochel@vti.se>2022-11-14 17:38:44 +0100
committerGitHub <noreply@github.com>2022-11-14 17:38:44 +0100
commita482a02915f361e56669ee9884ebee0eb6f2d8d5 (patch)
treeb62a8addad8f1e7084c55d3317d3d74947da3f50 /plugins
parentb70977b25657c193a3a6c0445b63325a420da646 (diff)
downloadzsh-a482a02915f361e56669ee9884ebee0eb6f2d8d5.tar.gz
zsh-a482a02915f361e56669ee9884ebee0eb6f2d8d5.tar.bz2
zsh-a482a02915f361e56669ee9884ebee0eb6f2d8d5.zip
feat(git-prompt): add option to show upstream branch (#11336)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/git-prompt/README.md2
-rw-r--r--plugins/git-prompt/git-prompt.plugin.zsh9
2 files changed, 10 insertions, 1 deletions
diff --git a/plugins/git-prompt/README.md b/plugins/git-prompt/README.md
index 8775af893..05208d72f 100644
--- a/plugins/git-prompt/README.md
+++ b/plugins/git-prompt/README.md
@@ -45,6 +45,7 @@ The symbols are as follows:
| ●n | there are `n` staged files |
| ✖n | there are `n` unmerged files |
| ✚n | there are `n` unstaged files |
+| -n | there are `n` deleted files |
| ⚑n | there are `n` stashed changes |
| … | there are some untracked files |
@@ -59,6 +60,7 @@ The symbols are as follows:
## Customisation
- Set the variable `ZSH_THEME_GIT_PROMPT_CACHE` to any value in order to enable caching.
+- Set the variable `ZSH_THEME_GIT_SHOW_UPSTREAM` to any value to display the upstream branch.
- You may also change a number of variables (whose name start with `ZSH_THEME_GIT_PROMPT_`)
to change the appearance of the prompt. Take a look at the bottom of the [plugin file](git-prompt.plugin.zsh)`
to see what variables are available.
diff --git a/plugins/git-prompt/git-prompt.plugin.zsh b/plugins/git-prompt/git-prompt.plugin.zsh
index dcda418cf..487332028 100644
--- a/plugins/git-prompt/git-prompt.plugin.zsh
+++ b/plugins/git-prompt/git-prompt.plugin.zsh
@@ -48,12 +48,18 @@ function update_current_git_vars() {
GIT_STASHED=$__CURRENT_GIT_STATUS[8]
GIT_CLEAN=$__CURRENT_GIT_STATUS[9]
GIT_DELETED=$__CURRENT_GIT_STATUS[10]
+
+ if [ -z ${ZSH_THEME_GIT_SHOW_UPSTREAM+x} ]; then
+ GIT_UPSTREAM=
+ else
+ GIT_UPSTREAM=$(git rev-parse --abbrev-ref --symbolic-full-name "@{upstream}" 2>/dev/null) && GIT_UPSTREAM="${ZSH_THEME_GIT_PROMPT_UPSTREAM_SEPARATOR}${GIT_UPSTREAM}"
+ fi
}
git_super_status() {
precmd_update_git_vars
if [ -n "$__CURRENT_GIT_STATUS" ]; then
- STATUS="$ZSH_THEME_GIT_PROMPT_PREFIX$ZSH_THEME_GIT_PROMPT_BRANCH$GIT_BRANCH%{${reset_color}%}"
+ STATUS="$ZSH_THEME_GIT_PROMPT_PREFIX$ZSH_THEME_GIT_PROMPT_BRANCH$GIT_BRANCH$GIT_UPSTREAM%{${reset_color}%}"
if [ "$GIT_BEHIND" -ne "0" ]; then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_BEHIND$GIT_BEHIND%{${reset_color}%}"
fi
@@ -101,6 +107,7 @@ ZSH_THEME_GIT_PROMPT_AHEAD="%{↑%G%}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%}%{…%G%}"
ZSH_THEME_GIT_PROMPT_STASHED="%{$fg_bold[blue]%}%{⚑%G%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}%{✔%G%}"
+ZSH_THEME_GIT_PROMPT_UPSTREAM_SEPARATOR="->"
# Set the prompt.
RPROMPT='$(git_super_status)'