From 47df726794c4bdbb0cbbde5d49c582ad1fb39e22 Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 20 Mar 2017 18:00:02 +0100 Subject: [PATCH 1/4] Wait with evaluation of the parts that contain the branch names until PS1 is rendered. --- gitprompt.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 9ff5b42d..03c109ae 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -496,11 +496,11 @@ function updatePrompt() { unset GIT_REMOTE fi - local GIT_UPSTREAM="${git_status_fields[2]}" + export GIT_UPSTREAM="${git_status_fields[2]}" + local GIT_FORMATTED_UPSTREAM="${GIT_PROMPT_UPSTREAM//_UPSTREAM_/\$GIT_UPSTREAM}" if [[ -z "${__GIT_PROMPT_SHOW_UPSTREAM}" || "^" == "$GIT_UPSTREAM" ]]; then unset GIT_UPSTREAM - else - GIT_UPSTREAM="${GIT_PROMPT_UPSTREAM//_UPSTREAM_/${GIT_UPSTREAM}}" + unset GIT_FORMATTED_UPSTREAM fi local GIT_STAGED=${git_status_fields[3]} @@ -512,7 +512,8 @@ function updatePrompt() { local NEW_PROMPT="$EMPTY_PROMPT" if [[ -n "$git_status_fields" ]]; then - local STATUS="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}${GIT_BRANCH}${ResetColor}" + local STATUS_PREFIX="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}\${GIT_BRANCH}${ResetColor}${GIT_FORMATTED_UPSTREAM}" + local STATUS="" # __add_status KIND VALEXPR INSERT # eg: __add_status 'STAGED' '-ne 0' @@ -542,7 +543,6 @@ function updatePrompt() { eval "STATUS=\"$STATUS$1\"" } - __add_status '$GIT_UPSTREAM' __chk_gitvar_status 'REMOTE' '-n' __add_status "$GIT_PROMPT_SEPARATOR" __chk_gitvar_status 'STAGED' '-ne 0' @@ -553,7 +553,7 @@ function updatePrompt() { __chk_gitvar_status 'CLEAN' '-eq 1' - __add_status "$ResetColor$GIT_PROMPT_SUFFIX" - NEW_PROMPT="$(gp_add_virtualenv_to_prompt)$PROMPT_START$($prompt_callback)$STATUS$PROMPT_END" + NEW_PROMPT="$(gp_add_virtualenv_to_prompt)$PROMPT_START$($prompt_callback)$STATUS_PREFIX$STATUS$PROMPT_END" else NEW_PROMPT="$EMPTY_PROMPT" fi From 737ebec4c064ee6ce1624129d9548af3b55a5f4e Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 20 Mar 2017 20:11:44 +0100 Subject: [PATCH 2/4] Move the local variable to the else branch so that you don't do an unnecessary substitution --- gitprompt.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 03c109ae..4c7eea81 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -497,10 +497,11 @@ function updatePrompt() { fi export GIT_UPSTREAM="${git_status_fields[2]}" - local GIT_FORMATTED_UPSTREAM="${GIT_PROMPT_UPSTREAM//_UPSTREAM_/\$GIT_UPSTREAM}" if [[ -z "${__GIT_PROMPT_SHOW_UPSTREAM}" || "^" == "$GIT_UPSTREAM" ]]; then unset GIT_UPSTREAM unset GIT_FORMATTED_UPSTREAM + else + local GIT_FORMATTED_UPSTREAM="${GIT_PROMPT_UPSTREAM//_UPSTREAM_/\$GIT_UPSTREAM}" fi local GIT_STAGED=${git_status_fields[3]} From 230717084bdbe0f4cd27d60ec3f88c08cba5e0d8 Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 20 Mar 2017 20:23:25 +0100 Subject: [PATCH 3/4] Remove unnecessary unset of the local variable --- gitprompt.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 4c7eea81..7665662c 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -499,7 +499,6 @@ function updatePrompt() { export GIT_UPSTREAM="${git_status_fields[2]}" if [[ -z "${__GIT_PROMPT_SHOW_UPSTREAM}" || "^" == "$GIT_UPSTREAM" ]]; then unset GIT_UPSTREAM - unset GIT_FORMATTED_UPSTREAM else local GIT_FORMATTED_UPSTREAM="${GIT_PROMPT_UPSTREAM//_UPSTREAM_/\$GIT_UPSTREAM}" fi From 46aaea2c334345162f5ec54f1e44beea32d50a1b Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 20 Mar 2017 21:02:12 +0100 Subject: [PATCH 4/4] Postpone export of GIT_UPSTREAM until we know that it should be exported --- gitprompt.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 7665662c..5015a622 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -496,10 +496,11 @@ function updatePrompt() { unset GIT_REMOTE fi - export GIT_UPSTREAM="${git_status_fields[2]}" - if [[ -z "${__GIT_PROMPT_SHOW_UPSTREAM}" || "^" == "$GIT_UPSTREAM" ]]; then + local GIT_UPSTREAM_PRIVATE="${git_status_fields[2]}" + if [[ -z "${__GIT_PROMPT_SHOW_UPSTREAM}" || "^" == "$GIT_UPSTREAM_PRIVATE" ]]; then unset GIT_UPSTREAM else + export GIT_UPSTREAM=${GIT_UPSTREAM_PRIVATE} local GIT_FORMATTED_UPSTREAM="${GIT_PROMPT_UPSTREAM//_UPSTREAM_/\$GIT_UPSTREAM}" fi