From a482a02915f361e56669ee9884ebee0eb6f2d8d5 Mon Sep 17 00:00:00 2001 From: Lennart Ochel Date: Mon, 14 Nov 2022 17:38:44 +0100 Subject: [PATCH] feat(git-prompt): add option to show upstream branch (#11336) --- plugins/git-prompt/README.md | 2 ++ plugins/git-prompt/git-prompt.plugin.zsh | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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)'