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
This commit is contained in:
parent
a06da7bafe
commit
041e6eb1c5
22
bin/ls/ls.1
22
bin/ls/ls.1
@ -32,7 +32,7 @@
|
|||||||
.\" @(#)ls.1 8.7 (Berkeley) 7/29/94
|
.\" @(#)ls.1 8.7 (Berkeley) 7/29/94
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd August 16, 2018
|
.Dd August 18, 2018
|
||||||
.Dt LS 1
|
.Dt LS 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -252,6 +252,26 @@ environment variable is set and not empty.
|
|||||||
.Pp
|
.Pp
|
||||||
.Cm never
|
.Cm never
|
||||||
will disable color regardless of environment variables.
|
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
|
.It Fl d
|
||||||
Directories are listed as plain files (not searched recursively).
|
Directories are listed as plain files (not searched recursively).
|
||||||
.It Fl f
|
.It Fl f
|
||||||
|
30
bin/ls/ls.c
30
bin/ls/ls.c
@ -200,6 +200,30 @@ do_color(void)
|
|||||||
return (do_color_from_env());
|
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
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -406,11 +430,11 @@ main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
#ifdef COLORLS
|
#ifdef COLORLS
|
||||||
case COLOR_OPT:
|
case COLOR_OPT:
|
||||||
if (optarg == NULL || strcmp(optarg, "always") == 0)
|
if (optarg == NULL || do_color_always(optarg))
|
||||||
colorflag = COLORFLAG_ALWAYS;
|
colorflag = COLORFLAG_ALWAYS;
|
||||||
else if (strcmp(optarg, "auto") == 0)
|
else if (do_color_auto(optarg))
|
||||||
colorflag = COLORFLAG_AUTO;
|
colorflag = COLORFLAG_AUTO;
|
||||||
else if (strcmp(optarg, "never") == 0)
|
else if (do_color_never(optarg))
|
||||||
colorflag = COLORFLAG_NEVER;
|
colorflag = COLORFLAG_NEVER;
|
||||||
else
|
else
|
||||||
errx(2, "unsupported --color value '%s' (must be always, auto, or never)",
|
errx(2, "unsupported --color value '%s' (must be always, auto, or never)",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user