From owner-svn-src-stable@freebsd.org Fri Jun 5 02:56:43 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5D7A333C458; Fri, 5 Jun 2020 02:56:43 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49dS3H1kMLz3VnX; Fri, 5 Jun 2020 02:56:43 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 365C1A0EE; Fri, 5 Jun 2020 02:56:43 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0552ug5F012271; Fri, 5 Jun 2020 02:56:42 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0552ugee012269; Fri, 5 Jun 2020 02:56:42 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202006050256.0552ugee012269@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Fri, 5 Jun 2020 02:56:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r361818 - stable/12/bin/ls X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/12/bin/ls X-SVN-Commit-Revision: 361818 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jun 2020 02:56:43 -0000 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;