]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
terminal-colors.d: support NO_COLOR
authorKarel Zak <kzak@redhat.com>
Mon, 17 Mar 2025 12:38:20 +0000 (13:38 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 17 Mar 2025 12:38:20 +0000 (13:38 +0100)
We already provide the ability to easily disable output colorization,
but there is also the https://no-color.org initiative based on the
NO_COLOR environment variable. Let's support this method to disable
colors. Let's be friendly :-)

Addresses: https://github.com/util-linux/util-linux/issues/3463
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/colors.c
lib/terminal-colors.d.5.adoc
man-common/colors.adoc

index 565a7171ba8c321ec2b34ea33ff0a9bcda6aafc1..190459803b0c70ce2d89f2b651225b4393c2776c 100644 (file)
@@ -600,7 +600,9 @@ int colors_init(int mode, const char *name)
                cc->mode = mode;
 
        if (cc->mode == UL_COLORMODE_UNDEF
+           && getenv("NO_COLOR") == NULL
            && (ready = colors_terminal_is_ready())) {
+
                int rc = colors_read_configuration(cc);
                if (rc)
                        cc->mode = UL_COLORMODE_DEFAULT;
index f09cce1b7598f38b220a9cd8f76568db0648a49f..ed8c4872712963a55b4c7dd2600b41120549ab26 100644 (file)
@@ -33,8 +33,7 @@ The _term_ is a terminal identifier (the *TERM* environment variable). The termi
 The _type_ is a file type. Supported file types are:
 
 *disable*::
-Turns off output colorization for all compatible utilities.
-
+Turns off output colorization for all compatible utilities. See also the NO_COLOR environment variable below.
 *enable*::
 Turns on output colorization; any matching *disable* files are ignored.
 
@@ -131,6 +130,11 @@ Lines where the first non-blank character is a # (hash) are ignored. Any other u
 *TERMINAL_COLORS_DEBUG*=all::
 enables debug output.
 
+*NO_COLOR*::
+if defined, this disables output colorization unless explicitly enabled by a
+command-line option. See https://no-color.org/ for more details. Supported
+since util-linux version 2.41.
+
 == FILES
 
 _$XDG_CONFIG_HOME/terminal-colors.d_
index a693f87f62557273b2ea6aadb1fd0f59cec69d6d..0b883ee5bd2f5e93626fe598e8d1daca9bed15e6 100644 (file)
@@ -9,6 +9,9 @@ for the *{command}* command or for all tools by
 ____
 _/etc/terminal-colors.d/disable_
 ____
+Since version 2.41, the $NO_COLOR environment variable is also supported to
+disable output colorization unless explicitly enabled by a command-line option.
+
 The user-specific _$XDG_CONFIG_HOME/terminal-colors.d_
 or _$HOME/.config/terminal-colors.d_ overrides the global setting.