[PATCH] git-prompt: fix expansion of branch colour codes
- From
Joakim Petersen <joak-pet@online.no>
- Date
- Jun 9, 2022, 20:44 UTC
- Message-ID
- <20220609204447.32841-1-joak-pet@online.no>
- In-Reply-To
- <20220607115024.64724-1-joak-pet@online.no>
Because of the wrapping of the branch name variable $b, the colour codes in the variable don't get applied, but are instead printed directly in the output. Move the wrapping of $b to before colour codes are inserted to correct this.
Signed-off-by: Joakim Petersen <joak-pet@online.no> --- contrib/completion/git-prompt.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index cb01c2fd5d..1435548e00 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -556,9 +556,14 @@ __git_ps1 () fi fi - b=${b##refs/heads/} local z="${GIT_PS1_STATESEPARATOR-" "}" + b=${b##refs/heads/} + if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then + __git_ps1_branch_name=$b + b="\${__git_ps1_branch_name}" + fi + # NO color option unless in PROMPT_COMMAND mode or it's Zsh if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then @@ -566,11 +571,6 @@ __git_ps1 () fi fi - if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then - __git_ps1_branch_name=$b - b="\${__git_ps1_branch_name}" - fi - local f="$h$w$i$s$u$p" local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}" base-commit: 9470605a1b03dac8fc4f801132e36964b4fbb8c3
-- 2.36.1