summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2018-08-18 20:55:20 +0000
committerKyle Evans <kevans@FreeBSD.org>2018-08-18 20:55:20 +0000
commit041e6eb1c5c9c50ec82679cd3e04d028997ecc4f (patch)
tree7ad3bf9583be37dfa953c8d6173a4a58457f523d
parenta06da7bafef42710a0cad0846f3c4face8ad5c84 (diff)
Notes
-rw-r--r--bin/ls/ls.122
-rw-r--r--bin/ls/ls.c30
2 files changed, 48 insertions, 4 deletions
diff --git a/bin/ls/ls.1 b/bin/ls/ls.1
index 6f4303a349a17..dde947be98759 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 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
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 9a8e855176eba..19effce3d1956 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -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)",