diff options
author | Thomas Haller <thaller@redhat.com> | 2023-09-14 15:24:58 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2023-09-25 09:02:17 +0000 |
commit | ae06a607b3ac6149e168c94cb752d0d69736adf1 (patch) | |
tree | 5437dfa9d4ec4839d50d9e7d84a714b8e688f382 | |
parent | 0ac5221c40f3b3d47533fc80b23a852278e259df (diff) |
cli: honor CLICOLOR_FORCE= variable to enable colors with nmclith/clicolor-force
Note that [1] suggests to also accept an empty value as having the variable
set. That is likely a bug ([2]) in the documentation, makes little sense, and
is not the case with NO_COLOR ([3]).
[1] https://bixense.com/clicolors/
[2] https://github.com/jhasse/clicolors/issues/13
[3] https://no-color.org/
-rw-r--r-- | man/nmcli.xml | 3 | ||||
-rw-r--r-- | src/nmcli/nmcli.c | 4 |
2 files changed, 5 insertions, 2 deletions
diff --git a/man/nmcli.xml b/man/nmcli.xml index 0404c55e29..9bda9db0af 100644 --- a/man/nmcli.xml +++ b/man/nmcli.xml @@ -130,7 +130,8 @@ Please refer to the <link linkend='colors' endterm='colors.title' /> section for a list of color names supported by <command>nmcli</command>.</para> <para>If the environment variable <literal>NO_COLOR</literal> is set (to any non-empty value), - then coloring is disabled with mode "auto". Explicitly enabling coloring overrides + then coloring is disabled with mode "auto". If the environment variable <literal>CLICOLOR_FORCE</literal> + is set (to any non-empty value), then coloring is enabled with mode "auto". Explicitly enabling coloring overrides the environment variable.</para> </listitem> </varlistentry> diff --git a/src/nmcli/nmcli.c b/src/nmcli/nmcli.c index 82df12ee8d..6de42faa00 100644 --- a/src/nmcli/nmcli.c +++ b/src/nmcli/nmcli.c @@ -489,7 +489,9 @@ check_colors(NmcColorOption color_option, char **out_palette_str) term = g_getenv("TERM"); if (color_option == NMC_USE_COLOR_AUTO) { - if (nm_streq0(term, "dumb") || !isatty(STDOUT_FILENO)) + if (nm_str_not_empty(g_getenv("CLICOLOR_FORCE"))) { + color_option = NMC_USE_COLOR_YES; + } else if (nm_streq0(term, "dumb") || !isatty(STDOUT_FILENO)) return FALSE; } |