From owner-svn-src-head@freebsd.org Thu Aug 16 01:27:17 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0F6581077588; Thu, 16 Aug 2018 01:27:17 +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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B94E087195; Thu, 16 Aug 2018 01:27:16 +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 9B99F1283C; Thu, 16 Aug 2018 01:27:16 +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 w7G1RGEn011483; Thu, 16 Aug 2018 01:27:16 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7G1RGZr011482; Thu, 16 Aug 2018 01:27:16 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808160127.w7G1RGZr011482@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 16 Aug 2018 01:27:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r337885 - head/bin/ls X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/bin/ls X-SVN-Commit-Revision: 337885 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Aug 2018 01:27:17 -0000 Author: kevans Date: Thu Aug 16 01:27:16 2018 New Revision: 337885 URL: https://svnweb.freebsd.org/changeset/base/337885 Log: ls(1): Fix color env var checking CLICOLOR will behavior as always- if present at all in the environment, allow colors. COLORTERM, recently enforced, will have to be both present and not empty. Submitted by: imp Modified: head/bin/ls/ls.c Modified: head/bin/ls/ls.c ============================================================================== --- head/bin/ls/ls.c Thu Aug 16 01:18:20 2018 (r337884) +++ head/bin/ls/ls.c Thu Aug 16 01:27:16 2018 (r337885) @@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -152,6 +153,29 @@ char *enter_bold; /* ANSI sequence to set color to bo static int rval; +static bool +do_color_from_env(void) +{ + const char *p; + bool doit; + + doit = false; + p = getenv("CLICOLOR"); + if (p == NULL) { + /* + * COLORTERM is the more standard name for this variable. We'll + * honor it as long as it's both set and not empty. + */ + p = getenv("COLORTERM"); + if (p != NULL && *p != '\0') + doit = true; + } else + doit = true; + + return (doit && + (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE"))); +} + int main(int argc, char *argv[]) { @@ -368,8 +392,7 @@ main(int argc, char *argv[]) f_listdot = 1; /* Enabling of colours is conditional on the environment. */ - if ((getenv("CLICOLOR") || getenv("COLORTERM")) && - (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE"))) + if (do_color_from_env()) #ifdef COLORLS if (tgetent(termcapbuf, getenv("TERM")) == 1) { ansi_fgcol = tgetstr("AF", &bp);