@@ -245,7 +245,8 @@ __git_ps1_show_upstream ()
245
245
246
246
# Helper function that is meant to be called from __git_ps1. It
247
247
# injects color codes into the appropriate gitstring variables used
248
- # to build a gitstring.
248
+ # to build a gitstring. Colored variables are responsible for clearing
249
+ # their own color.
249
250
__git_ps1_colorize_gitstring ()
250
251
{
251
252
if [[ -n ${ZSH_VERSION-} ]]; then
@@ -271,22 +272,23 @@ __git_ps1_colorize_gitstring ()
271
272
else
272
273
branch_color=" $bad_color "
273
274
fi
274
- c=" $branch_color$c "
275
+ if [ -n " $c " ]; then
276
+ c=" $branch_color$c$c_clear "
277
+ fi
278
+ b=" $branch_color$b$c_clear "
275
279
276
- z=" $c_clear$z "
277
- if [ " $w " = " *" ]; then
278
- w=" $bad_color$w "
280
+ if [ -n " $w " ]; then
281
+ w=" $bad_color$w$c_clear "
279
282
fi
280
283
if [ -n " $i " ]; then
281
- i=" $ok_color$i "
284
+ i=" $ok_color$i$c_clear "
282
285
fi
283
286
if [ -n " $s " ]; then
284
- s=" $flags_color$s "
287
+ s=" $flags_color$s$c_clear "
285
288
fi
286
289
if [ -n " $u " ]; then
287
- u=" $bad_color$u "
290
+ u=" $bad_color$u$c_clear "
288
291
fi
289
- r=" $c_clear$r "
290
292
}
291
293
292
294
# Helper function to read the first line of a file into a variable.
@@ -556,19 +558,19 @@ __git_ps1 ()
556
558
557
559
local z=" ${GIT_PS1_STATESEPARATOR-" " } "
558
560
561
+ b=${b## refs/ heads/ }
562
+ if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
563
+ __git_ps1_branch_name=$b
564
+ b=" \$ {__git_ps1_branch_name}"
565
+ fi
566
+
559
567
# NO color option unless in PROMPT_COMMAND mode or it's Zsh
560
568
if [ -n " ${GIT_PS1_SHOWCOLORHINTS-} " ]; then
561
569
if [ $pcmode = yes ] || [ -n " ${ZSH_VERSION-} " ]; then
562
570
__git_ps1_colorize_gitstring
563
571
fi
564
572
fi
565
573
566
- b=${b## refs/ heads/ }
567
- if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
568
- __git_ps1_branch_name=$b
569
- b=" \$ {__git_ps1_branch_name}"
570
- fi
571
-
572
574
local f=" $h$w$i$s$u$p "
573
575
local gitstring=" $c$b ${f: +$z$f }${sparse} $r ${upstream} "
574
576
0 commit comments