Skip to content

Commit ea625a3

Browse files
felipecgitster
authored andcommitted
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>
1 parent 98fc268 commit ea625a3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

contrib/completion/git-prompt.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@
9797
# If you would like a colored hint about the current dirty state, set
9898
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
9999
# 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.
101102
#
102103
# If you would like __git_ps1 to do nothing in the case when the current
103104
# directory is set up to be ignored by git, then set
@@ -553,9 +554,11 @@ __git_ps1 ()
553554

554555
local z="${GIT_PS1_STATESEPARATOR-" "}"
555556

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
559562
fi
560563

561564
b=${b##refs/heads/}

0 commit comments

Comments
 (0)