summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2020-05-21 14:39:00 +0000
committerKyle Evans <kevans@FreeBSD.org>2020-05-21 14:39:00 +0000
commita408dc201879e70e6508f4269e031616739fc5a0 (patch)
tree0c04268a27c330231b14c02bbc25295d8fc13595 /bin
parente165a15b5f1eaa7d2d7edb907e87d04c8e03c060 (diff)
downloadsrc-test-a408dc201879e70e6508f4269e031616739fc5a0.tar.gz
src-test-a408dc201879e70e6508f4269e031616739fc5a0.zip
ls(1): actually restore proper behavior
Highlights: - CLICOLOR in the environment should imply --color=auto to maintain compatibility with historical behavior - -G should set CLICOLOR and imply --color=auto The manpage has been updated to draw the connection between -G and --color; the former is in-fact a sort of compromise between --color=always and --color=auto, where we'll output color regardless of the environment lacking CLICOLOR/COLORTERM assuming stdout is a tty. X-MFC-With: r361318
Notes
Notes: svn path=/head/; revision=361331
Diffstat (limited to 'bin')
-rw-r--r--bin/ls/ls.15
-rw-r--r--bin/ls/ls.c13
2 files changed, 16 insertions, 2 deletions
diff --git a/bin/ls/ls.1 b/bin/ls/ls.1
index edce3491b50b7..83d8fc14198a8 100644
--- a/bin/ls/ls.1
+++ b/bin/ls/ls.1
@@ -32,7 +32,7 @@
.\" @(#)ls.1 8.7 (Berkeley) 7/29/94
.\" $FreeBSD$
.\"
-.Dd May 20, 2020
+.Dd May 21, 2020
.Dt LS 1
.Os
.Sh NAME
@@ -135,7 +135,8 @@ This option is equivalent to defining
.Ev CLICOLOR
or
.Ev COLORTERM
-in the environment.
+in the environment and setting
+.Fl -color Ns = Ns Ar auto .
(See below.)
This functionality can be compiled out by removing the definition of
.Ev COLORLS .
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 681570e552b20..edf4b49bf0e8f 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -265,6 +265,13 @@ main(int argc, char *argv[])
fts_options = FTS_PHYSICAL;
if (getenv("LS_SAMESORT"))
f_samesort = 1;
+
+ /*
+ * For historical compatibility, we'll use our autodetection if CLICOLOR
+ * is set.
+ */
+ if (getenv("CLICOLOR"))
+ colorflag = COLORFLAG_AUTO;
while ((ch = getopt_long(argc, argv,
"+1ABCD:FGHILPRSTUWXZabcdfghiklmnopqrstuwxy,", long_opts,
NULL)) != -1) {
@@ -342,7 +349,13 @@ main(int argc, char *argv[])
f_slash = 0;
break;
case 'G':
+ /*
+ * We both set CLICOLOR here and set colorflag to
+ * COLORFLAG_AUTO, because -G should not force color if
+ * stdout isn't a tty.
+ */
setenv("CLICOLOR", "", 1);
+ colorflag = COLORFLAG_AUTO;
break;
case 'H':
fts_options |= FTS_COMFOLLOW;