feat(git-prompt): add option to show upstream branch (#11336)

This commit is contained in:
Lennart Ochel 2022-11-14 17:38:44 +01:00 committed by GitHub
parent b70977b256
commit a482a02915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -45,6 +45,7 @@ The symbols are as follows:
| ●n | there are `n` staged files | | ●n | there are `n` staged files |
| ✖n | there are `n` unmerged files | | ✖n | there are `n` unmerged files |
| ✚n | there are `n` unstaged files | | ✚n | there are `n` unstaged files |
| -n | there are `n` deleted files |
| ⚑n | there are `n` stashed changes | | ⚑n | there are `n` stashed changes |
| … | there are some untracked files | | … | there are some untracked files |
@ -59,6 +60,7 @@ The symbols are as follows:
## Customisation ## Customisation
- Set the variable `ZSH_THEME_GIT_PROMPT_CACHE` to any value in order to enable caching. - 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_`) - 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 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. to see what variables are available.

View File

@ -48,12 +48,18 @@ function update_current_git_vars() {
GIT_STASHED=$__CURRENT_GIT_STATUS[8] GIT_STASHED=$__CURRENT_GIT_STATUS[8]
GIT_CLEAN=$__CURRENT_GIT_STATUS[9] GIT_CLEAN=$__CURRENT_GIT_STATUS[9]
GIT_DELETED=$__CURRENT_GIT_STATUS[10] 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() { git_super_status() {
precmd_update_git_vars precmd_update_git_vars
if [ -n "$__CURRENT_GIT_STATUS" ]; then 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 if [ "$GIT_BEHIND" -ne "0" ]; then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_BEHIND$GIT_BEHIND%{${reset_color}%}" STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_BEHIND$GIT_BEHIND%{${reset_color}%}"
fi fi
@ -101,6 +107,7 @@ ZSH_THEME_GIT_PROMPT_AHEAD="%{↑%G%}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%}%{…%G%}" ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%}%{…%G%}"
ZSH_THEME_GIT_PROMPT_STASHED="%{$fg_bold[blue]%}%{⚑%G%}" ZSH_THEME_GIT_PROMPT_STASHED="%{$fg_bold[blue]%}%{⚑%G%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}%{✔%G%}" ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}%{✔%G%}"
ZSH_THEME_GIT_PROMPT_UPSTREAM_SEPARATOR="->"
# Set the prompt. # Set the prompt.
RPROMPT='$(git_super_status)' RPROMPT='$(git_super_status)'