completion: prompt: fix color for Zsh
We don't need PROMPT_COMMAND in Zsh; we are already using %F{color} %f, which in turn use %{ and %}, which are the equivalent of Bash's \[ and \]. We can use as many colors as we want and output directly into PS1 (or RPS1) without the risk of buffer wrapping issues. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Oct 27, 2020 at 20:06 UTC
ea625a39fe5dfcaa3df0d1ee53a40008213acd59
1 file changed
+7
-4
contrib/completion/git-prompt.sh
+7
-4
@@ -97,7 +97,8 @@
97
# If you would like a colored hint about the current dirty state, set
98
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
99
# the colored output of "git status -sb" and are available only when
100
-# using __git_ps1 for PROMPT_COMMAND or precmd.
100
+# using __git_ps1 for PROMPT_COMMAND or precmd in Bash,
101
+# but always available in Zsh.
102
#
103
# If you would like __git_ps1 to do nothing in the case when the current
104
# directory is set up to be ignored by git, then set
@@ -553,9 +554,11 @@ __git_ps1 ()
554
555
local z="${GIT_PS1_STATESEPARATOR-" "}"
556
556
- # NO color option unless in PROMPT_COMMAND mode
557
- if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
558
- __git_ps1_colorize_gitstring
557
+ # NO color option unless in PROMPT_COMMAND mode or it's Zsh
558
+ if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
559
+ if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
560
+ __git_ps1_colorize_gitstring
561
+ fi
562
fi
563
564
b=${b##refs/heads/}