directory merely because it was removed. This reverts a change
that was made in release 8.32.
+** New Features
+
+ ls --classify now supports the "always", "auto", or "never" flags,
+ to support only outputting classifier characters if connected to a tty.
+
* Noteworthy changes in release 8.32 (2020-03-05) [stable]
will perform only one @code{stat} call per command line argument.
@item -F
-@itemx --classify
+@itemx --classify [=@var{when}]
@itemx --indicator-style=classify
@opindex -F
@opindex --classify
indicators are @samp{/} for directories, @samp{@@} for symbolic links,
@samp{|} for FIFOs, @samp{=} for sockets, @samp{>} for doors,
and nothing for regular files.
+@var{when} may be omitted, or one of:
+@itemize @bullet
+@item none
+@vindex none @r{classify option}
+- Do not classify. This is the default.
+@item auto
+@vindex auto @r{classify option}
+@cindex terminal, using classify iff
+- Only classify if standard output is a terminal.
+@item always
+@vindex always @r{classify option}
+- Always classify.
+@end itemize
+Specifying @option{--classify} and no @var{when} is equivalent to
+@option{--classify=always}.
@c The following sentence is the same as the one for -d.
Do not follow symbolic links listed on the
command line unless the @option{--dereference-command-line} (@option{-H}),
{"width", required_argument, NULL, 'w'},
{"almost-all", no_argument, NULL, 'A'},
{"ignore-backups", no_argument, NULL, 'B'},
- {"classify", no_argument, NULL, 'F'},
+ {"classify", optional_argument, NULL, 'F'},
{"file-type", no_argument, NULL, FILE_TYPE_INDICATOR_OPTION},
{"si", no_argument, NULL, SI_OPTION},
{"dereference-command-line", no_argument, NULL, 'H'},
break;
case 'F':
- indicator_style = classify;
- break;
+ {
+ int i;
+ if (optarg)
+ i = XARGMATCH ("--classify", optarg, when_args, when_types);
+ else
+ /* Using --classify with no argument is equivalent to using
+ --classify=always. */
+ i = when_always;
+
+ if (i == when_always
+ || (i == when_if_tty && isatty (STDOUT_FILENO)))
+ indicator_style = classify;
+ break;
+ }
case 'G': /* inhibit display of group info */
print_group = false;
"), stdout);
fputs (_("\
-f do not sort, enable -aU, disable -ls --color\n\
- -F, --classify append indicator (one of */=>@|) to entries\n\
+ -F, --classify[=WHEN] append indicator (one of */=>@|) to entries;\n\
+ WHEN can be 'always' (default if omitted),\n\
+ 'auto', or 'never'\n\
--file-type likewise, except do not append '*'\n\
--format=WORD across -x, commas -m, horizontal -x, long -l,\n\
single-column -1, verbose -l, vertical -C\n\
tests/ls/abmon-align.sh \
tests/ls/birthtime.sh \
tests/ls/block-size.sh \
+ tests/ls/classify.sh \
tests/ls/color-clear-to-eol.sh \
tests/ls/color-dtype-dir.sh \
tests/ls/color-norm.sh \
--- /dev/null
+#!/bin/sh
+# Test --classify processing
+
+# Copyright (C) 2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ ls
+
+mkdir testdir || framework_failure_
+cd testdir || framework_failure_
+mkdir dir || framework_failure_
+touch regular executable || framework_failure_
+chmod a+x executable || framework_failure_
+ln -s regular slink-reg || framework_failure_
+ln -s dir slink-dir || framework_failure_
+ln -s nowhere slink-dangle || framework_failure_
+mknod block b 20 20 2> /dev/null && block="block
+"
+mknod char c 10 10 2> /dev/null && char="char
+"
+mkfifo_or_skip_ fifo
+cd ..
+
+cat <<EOF > exp
+$block${char}dir/
+executable*
+fifo|
+regular
+slink-dangle@
+slink-dir@
+slink-reg@
+EOF
+sed 's/[*/@|]//' exp > exp2 || framework_failure_
+
+ls --classify testdir > out || fail=1
+ls --classify=always testdir > out2 || fail=1
+ls --classify=auto testdir > out3 || fail=1
+ls --classify=never testdir > out4 || fail=1
+
+compare exp out || fail=1
+
+compare exp out2 || fail=1
+
+compare exp2 out3 || fail=1
+
+compare exp2 out4 || fail=1
+
+returns_ 1 ls --classify=invalid || fail=1
+
+Exit $fail