From 881a3c8dd0f4dc74acd4e1b7048173df4f9ea3e2 Mon Sep 17 00:00:00 2001 From: Brandon Groves Date: Wed, 30 Nov 2016 10:40:00 -0500 Subject: [PATCH] git - display upstream remote/branch for the given local branch --- lib/git.zsh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index f7eccb81..591887f0 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -4,7 +4,16 @@ function git_prompt_info() { if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then ref=$(command git symbolic-ref HEAD 2> /dev/null) || \ ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0 - echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" + echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_upstream_branch)$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" + fi +} + +# Display upstream remote branch name +function parse_git_upstream_branch() { + if [[ $(git rev-parse --abbrev-ref HEAD 2> /dev/null) != 'HEAD' ]]; then + if [[ "$(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD))" ]]; then + echo " $ZSH_THEME_GIT_UPSTREAM_REMOTE $(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD))" + fi fi }