svn commit: r361818 - stable/12/bin/ls

Kyle Evans kevans at FreeBSD.org
Fri Jun 5 02:56:43 UTC 2020


Author: kevans
Date: Fri Jun  5 02:56:42 2020
New Revision: 361818
URL: https://svnweb.freebsd.org/changeset/base/361818

Log:
  MFC r361318, r361331-r361332
  
  r361318:
  ls: fix a --color regression from r337956
  
  The regression is in-fact that I flipped the default from never to auto. The
  incorrect impression was based on an alias that I failed to notice,
  installed by the Linux distribution that I used for testing compatibility
  here. Users that want the old default should be doing so with a shell alias
  as is done elsewhere, rather than making this decision in ls(1).
  
  Many thanks to rgrimes for pointing out the alias that I clearly overlooked
  that resulted in this; if you despised colors in your terminal from this,
  consider buying him a beer at the next venue that you see him at.
  
  r361331:
  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.
  
  r361332:
  ls: fix WITHOUT_LS_COLORS build
  
  *sigh* references to colorflags should be gated by COLORLS.
  
  Relnotes:	yes

Modified:
  stable/12/bin/ls/ls.1
  stable/12/bin/ls/ls.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/bin/ls/ls.1
==============================================================================
--- stable/12/bin/ls/ls.1	Fri Jun  5 02:52:07 2020	(r361817)
+++ stable/12/bin/ls/ls.1	Fri Jun  5 02:56:42 2020	(r361818)
@@ -32,7 +32,7 @@
 .\"     @(#)ls.1	8.7 (Berkeley) 7/29/94
 .\" $FreeBSD$
 .\"
-.Dd August 18, 2018
+.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 .
@@ -216,8 +217,8 @@ Output colored escape sequences based on
 .Ar when ,
 which may be set to either
 .Cm always ,
-.Cm auto
-(default), or
+.Cm auto ,
+or
 .Cm never .
 .Pp
 .Cm always
@@ -252,6 +253,12 @@ environment variable is set and not empty.
 .Pp
 .Cm never
 will disable color regardless of environment variables.
+.Cm never
+is the default when neither
+.Fl -color
+nor
+.Fl G
+is specified.
 .Pp
 For compatibility with GNU coreutils,
 .Nm

Modified: stable/12/bin/ls/ls.c
==============================================================================
--- stable/12/bin/ls/ls.c	Fri Jun  5 02:52:07 2020	(r361817)
+++ stable/12/bin/ls/ls.c	Fri Jun  5 02:56:42 2020	(r361818)
@@ -152,7 +152,7 @@ static int f_timesort;		/* sort by time vice name */
        int f_type;		/* add type character for non-regular files */
 static int f_whiteout;		/* show whiteout entries */
 #ifdef COLORLS
-       int colorflag = COLORFLAG_AUTO;		/* passed in colorflag */
+       int colorflag = COLORFLAG_NEVER;		/* passed in colorflag */
        int f_color;		/* add type in color for non-regular files */
        bool explicitansi;	/* Explicit ANSI sequences, no termcap(5) */
 char *ansi_bgcol;		/* ANSI sequence to set background colour */
@@ -265,6 +265,15 @@ 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.
+	 */
+#ifdef COLORLS
+	if (getenv("CLICOLOR"))
+		colorflag = COLORFLAG_AUTO;
+#endif
 	while ((ch = getopt_long(argc, argv,
 	    "+1ABCD:FGHILPRSTUWXZabcdfghiklmnopqrstuwxy,", long_opts,
 	    NULL)) != -1) {
@@ -342,7 +351,15 @@ 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);
+#ifdef COLORLS
+			colorflag = COLORFLAG_AUTO;
+#endif
 			break;
 		case 'H':
 			fts_options |= FTS_COMFOLLOW;


More information about the svn-src-all mailing list