]> git.ipfire.org Git - thirdparty/git.git/commitdiff
completion: prompt: fix color for Zsh
authorFelipe Contreras <felipe.contreras@gmail.com>
Wed, 28 Oct 2020 02:06:50 +0000 (20:06 -0600)
committerJunio C Hamano <gitster@pobox.com>
Wed, 28 Oct 2020 21:30:59 +0000 (14:30 -0700)
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>
contrib/completion/git-prompt.sh

index 16260bab73346ba79d8e96eda03628d7dbd4b75b..54e123d632cd5cbc57215d9db7fae7b0981a01cf 100644 (file)
@@ -97,7 +97,8 @@
 # If you would like a colored hint about the current dirty state, set
 # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
 # the colored output of "git status -sb" and are available only when
-# using __git_ps1 for PROMPT_COMMAND or precmd.
+# using __git_ps1 for PROMPT_COMMAND or precmd in Bash,
+# but always available in Zsh.
 #
 # If you would like __git_ps1 to do nothing in the case when the current
 # directory is set up to be ignored by git, then set
@@ -553,9 +554,11 @@ __git_ps1 ()
 
        local z="${GIT_PS1_STATESEPARATOR-" "}"
 
-       # NO color option unless in PROMPT_COMMAND mode
-       if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
-               __git_ps1_colorize_gitstring
+       # 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
+                       __git_ps1_colorize_gitstring
+               fi
        fi
 
        b=${b##refs/heads/}