Message ID | 20220609204447.32841-1-joak-pet@online.no (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | git-prompt: fix expansion of branch colour codes | expand |
Joakim Petersen <joak-pet@online.no> writes: > 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(-) t9903 seems to fail with this, though...? > 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
On 10/06/2022 02:05, Junio C Hamano wrote: > t9903 seems to fail with this, though...? > Ah yes, sorry about that, I seem to have gotten a bit ahead of myself. Since the wrapping of $b was entirely moved to before colouring happens, the tests need to be reverted back to their state from before the previous commit, with the exception of the extra $c_clear in the test with two active indicators. I'll submit a v2 with this change shortly.
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}"
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(-) base-commit: 9470605a1b03dac8fc4f801132e36964b4fbb8c3