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

[RFC PATCH] color: respect the $NO_COLOR convention

From
LNLeah Neukirchen <leah@vuxu.org>
Date
Mar 1, 2018, 16:44 UTC
Message-ID
<87zi3reoez.fsf@gmail.com>

When the NO_COLOR environment variable is set to any value, default to disabling color, i.e. resolve 'auto' to false.

NO_COLOR (http://no-color.org/) is a comprehensive approach to disable colors by default for all tools:

> All command-line software which outputs text with ANSI color added
> should check for the presence of a NO_COLOR environment variable that,
> when present (regardless of its value), prevents the addition of ANSI
> color.
Signed-off-by: Leah Neukirchen <leah@vuxu.org>
---

This is a first stab at implementing NO_COLOR for git, effectively making it then behave like before colors were enabled by default.

I feel this should be documented somewhere, but I'm not sure where the best place is. Perhaps in config.ui, or the Git environment variables (but they all start with GIT_).

 color.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/color.c b/color.c
index d48dd947c..59e9c2459 100644
--- a/color.c
+++ b/color.c
@@ -326,6 +326,8 @@ int git_config_colorbool(const char *var, const char *value)
 
 static int check_auto_color(void)
 {
+	if (getenv("NO_COLOR"))
+		return 0;
 	if (color_stdout_is_tty < 0)
 		color_stdout_is_tty = isatty(1);
 	if (color_stdout_is_tty || (pager_in_use() && pager_use_color)) {
-- 
2.16.2
Next: Junio C Hamano
Message 1 of 6 in “color: respect the $NO_COLOR convention”
  1. color: respect the $NO_COLOR conventionLeah Neukirchen, Mar 1, 2018
  2. Junio C HamanoMar 1, 2018
  3. Leah NeukirchenMar 1, 2018
  4. Junio C HamanoMar 1, 2018
  5. brian m. carlsonMar 4, 2018
  6. Junio C HamanoMar 5, 2018

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.