From 59783a1ce07482493e20b6a8b0fc1bfc06ee047c Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 30 Jan 2024 14:04:28 +0000 Subject: ls: support NO_COLOR environment variable If the NO_COLOR environment variable is set and is not empty 'ls' won't output ANSI colour codes. This is an alternative to the existing approach of setting 'LS_COLORS=none'. See https://no-color.org/. Costs 24-32 bytes. (GitHub issue #382) --- coreutils/ls.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/coreutils/ls.c b/coreutils/ls.c index df4277fbd..52c43c731 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -1222,6 +1222,11 @@ int ls_main(int argc UNUSED_PARAM, char **argv) /* set G_show_color = 1/0 */ if (ENABLE_FEATURE_LS_COLOR_IS_DEFAULT && !is_TERM_dumb()) { char *p = getenv("LS_COLORS"); +# if ENABLE_PLATFORM_MINGW32 + /* No colour if unset or empty: https://no-color.org */ + char *no_c = getenv("NO_COLOR"); + if (!no_c || no_c[0] == '\0') +# endif /* LS_COLORS is unset, or (not empty && not "none") ? */ if (!p || (p[0] && strcmp(p, "none") != 0)) { if (isatty(STDOUT_FILENO)) { -- cgit v1.2.3-55-g6feb