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

__git_ps1_colorize__gitstring() in git_prompt.sh: colors are hardcoded?

From
Nnathdwek <nathdwek@ulb.ac.be>
Date
Oct 17, 2014, 17:30 UTC
Message-ID
<5441524C.6040302@ulb.ac.be>
Hello,

It seems to me that the colors used to indicate the repo's state in the prompt are hardcoded although the top comment says otherwise.

>From contrib/completion/git-contrib.sh:

[83]# 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.

[228]__git_ps1_colorize_gitstring ()
{
	if [[ -n ${ZSH_VERSION-} ]]; then
		local c_red='%F{red}'
		local c_green='%F{green}'
		local c_lblue='%F{blue}'
		local c_clear='%f'
	else
		# Using \[ and \] around colors is necessary to prevent
		# issues with command line editing/browsing/completion!
		local c_red='\[\e[31m\]'
		local c_green='\[\e[32m\]'
		local c_lblue='\[\e[1;34m\]'
		local c_clear='\[\e[0m\]'
	fi
	local bad_color=$c_red
	local ok_color=$c_green
	local flags_color="$c_lblue"
	local branch_color=""

As expected upon seeing this snippet, the color.status.<slot> entries in the git config file do modify the git status -sb output but don't modify the colors used in the prompt.

Regards,
Nathan
Next: Michael J Gruber
Message 1 of 2 in “__git_ps1_colorize__gitstring() in git_prompt.sh: colors are hardcoded?”
  1. nathdwekOct 17, 2014
  2. Michael J GruberOct 20, 2014

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.