From 597e4b2d1ede9dffbdabaa141a333a2c50bf2c21 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 7 Oct 2019 17:42:17 +0200 Subject: [PATCH] cli: honor NO_COLOR environment variable to prevent automatic ASCII colors See-also: https://no-color.org/ --- clients/cli/nmcli.c | 6 ++++++ man/nmcli.xml | 3 +++ 2 files changed, 9 insertions(+) diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index d53416498c..5fbd6d7261 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -456,6 +456,12 @@ check_colors (NmcColorOption color_option, return FALSE; } + if ( color_option == NMC_USE_COLOR_AUTO + && g_getenv ("NO_COLOR")) { + /* https://no-color.org/ */ + return FALSE; + } + term = g_getenv ("TERM"); if (color_option == NMC_USE_COLOR_AUTO) { diff --git a/man/nmcli.xml b/man/nmcli.xml index 203337693c..694ffc3aba 100644 --- a/man/nmcli.xml +++ b/man/nmcli.xml @@ -129,6 +129,9 @@ terminal-colors.d5. Please refer to the section for a list of color names supported by nmcli. + If the environment variable NO_COLOR is set (to any value), + then coloring is disabled with mode "auto". Explicitly enabling coloring overrides + the environment variable.