git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/5] completion: prompt: fix color for Zsh

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Jun 14, 2019, 06:50 UTC
Message-ID
<20190614065051.17774-6-felipe.contreras@gmail.com>
In-Reply-To
<20190614065051.17774-1-felipe.contreras@gmail.com>

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>
---
 contrib/completion/git-prompt.sh | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 983e419d2b..b57a9c96cb 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -88,7 +88,7 @@
 # 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 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
@@ -506,9 +506,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/}
-- 
2.22.0.rc2.dirty
Previous: Felipe Contreras
Message 6 of 6 in “contrib: completion: general zsh updates”
  1. 0/5 contrib: completion: general zsh updatesFelipe Contreras, Jun 14, 2019
  2. 1/5 completion: zsh: update installation instructionsFelipe Contreras, Jun 14, 2019
  3. 2/5 completion: zsh: fix for directories with spacesFelipe Contreras, Jun 14, 2019
  4. 3/5 completion: remove zsh hackFelipe Contreras, Jun 14, 2019
  5. 4/5 completion: zsh: improve main function selectionFelipe Contreras, Jun 14, 2019
  6. 5/5 completion: prompt: fix color for ZshFelipe Contreras, Jun 14, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.