diff options
author | Ron Yorston <rmy@pobox.com> | 2024-01-30 14:04:28 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-01-30 14:15:42 +0000 |
commit | 59783a1ce07482493e20b6a8b0fc1bfc06ee047c (patch) | |
tree | c1f73e38b0c6664a10aa4c25222209b1ec07d5c9 | |
parent | e90fe5ece9e76837fb438e90da77b29eff4e7456 (diff) | |
download | busybox-w32-59783a1ce07482493e20b6a8b0fc1bfc06ee047c.tar.gz busybox-w32-59783a1ce07482493e20b6a8b0fc1bfc06ee047c.tar.bz2 busybox-w32-59783a1ce07482493e20b6a8b0fc1bfc06ee047c.zip |
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)
-rw-r--r-- | coreutils/ls.c | 5 |
1 files changed, 5 insertions, 0 deletions
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) | |||
1222 | /* set G_show_color = 1/0 */ | 1222 | /* set G_show_color = 1/0 */ |
1223 | if (ENABLE_FEATURE_LS_COLOR_IS_DEFAULT && !is_TERM_dumb()) { | 1223 | if (ENABLE_FEATURE_LS_COLOR_IS_DEFAULT && !is_TERM_dumb()) { |
1224 | char *p = getenv("LS_COLORS"); | 1224 | char *p = getenv("LS_COLORS"); |
1225 | # if ENABLE_PLATFORM_MINGW32 | ||
1226 | /* No colour if unset or empty: https://no-color.org */ | ||
1227 | char *no_c = getenv("NO_COLOR"); | ||
1228 | if (!no_c || no_c[0] == '\0') | ||
1229 | # endif | ||
1225 | /* LS_COLORS is unset, or (not empty && not "none") ? */ | 1230 | /* LS_COLORS is unset, or (not empty && not "none") ? */ |
1226 | if (!p || (p[0] && strcmp(p, "none") != 0)) { | 1231 | if (!p || (p[0] && strcmp(p, "none") != 0)) { |
1227 | if (isatty(STDOUT_FILENO)) { | 1232 | if (isatty(STDOUT_FILENO)) { |