Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Aug 2018 20:55:21 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r338027 - head/bin/ls
Message-ID:  <201808182055.w7IKtL8e015490@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Sat Aug 18 20:55:20 2018
New Revision: 338027
URL: https://svnweb.freebsd.org/changeset/base/338027

Log:
  ls(1): Support other aliases for --color arguments used by GNU ls(1)
  
  These aliases are supported and documented in the man page. For now, they
  will not be mentioned in the error when an invalid argument is encountered,
  instead keeping that list to the shorter 'preferred' names of each argument.
  
  Reported by:	rgrimes

Modified:
  head/bin/ls/ls.1
  head/bin/ls/ls.c

Modified: head/bin/ls/ls.1
==============================================================================
--- head/bin/ls/ls.1	Sat Aug 18 20:43:53 2018	(r338026)
+++ head/bin/ls/ls.1	Sat Aug 18 20:55:20 2018	(r338027)
@@ -32,7 +32,7 @@
 .\"     @(#)ls.1	8.7 (Berkeley) 7/29/94
 .\" $FreeBSD$
 .\"
-.Dd August 16, 2018
+.Dd August 18, 2018
 .Dt LS 1
 .Os
 .Sh NAME
@@ -252,6 +252,26 @@ environment variable is set and not empty.
 .Pp
 .Cm never
 will disable color regardless of environment variables.
+.Pp
+For compatibility with GNU coreutils,
+.Nm
+supports
+.Cm yes
+or
+.Cm force
+as equivalent to
+.Cm always ,
+.Cm no
+or
+.Cm none
+as equivalent to
+.Cm never ,
+and
+.Cm tty
+or
+.Cm if-tty
+as equivalent to
+.Cm auto .
 .It Fl d
 Directories are listed as plain files (not searched recursively).
 .It Fl f

Modified: head/bin/ls/ls.c
==============================================================================
--- head/bin/ls/ls.c	Sat Aug 18 20:43:53 2018	(r338026)
+++ head/bin/ls/ls.c	Sat Aug 18 20:55:20 2018	(r338027)
@@ -200,6 +200,30 @@ do_color(void)
 	return (do_color_from_env());
 }
 
+static bool
+do_color_always(const char *term)
+{
+
+	return (strcmp(term, "always") == 0 || strcmp(term, "yes") == 0 ||
+	    strcmp(term, "force") == 0);
+}
+
+static bool
+do_color_never(const char *term)
+{
+
+	return (strcmp(term, "never") == 0 || strcmp(term, "no") == 0 ||
+	    strcmp(term, "none") == 0);
+}
+
+static bool
+do_color_auto(const char *term)
+{
+
+	return (strcmp(term, "auto") == 0 || strcmp(term, "tty") == 0 ||
+	    strcmp(term, "if-tty") == 0);
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -406,11 +430,11 @@ main(int argc, char *argv[])
 			break;
 #ifdef COLORLS
 		case COLOR_OPT:
-			if (optarg == NULL || strcmp(optarg, "always") == 0)
+			if (optarg == NULL || do_color_always(optarg))
 				colorflag = COLORFLAG_ALWAYS;
-			else if (strcmp(optarg, "auto") == 0)
+			else if (do_color_auto(optarg))
 				colorflag = COLORFLAG_AUTO;
-			else if (strcmp(optarg, "never") == 0)
+			else if (do_color_never(optarg))
 				colorflag = COLORFLAG_NEVER;
 			else
 				errx(2, "unsupported --color value '%s' (must be always, auto, or never)",



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808182055.w7IKtL8e015490>