coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/4] ls: have classify take optional argument


From: Jason Kim
Subject: [PATCH 1/4] ls: have classify take optional argument
Date: Sun, 19 Apr 2020 01:40:16 -0700

Have the `ls` `--classify` option take an optional argument for when to
classify ("always", "auto", "never"), just like the optional argument
for `--color`.  When the optional argument is not specified, default to
"always" for backwards compatibility.
---
 src/ls.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/ls.c b/src/ls.c
index 4acf5f44d..3362c5257 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -859,7 +859,7 @@ static struct option const long_options[] =
   {"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'},
@@ -2093,8 +2093,20 @@ decode_switches (int argc, char **argv)
           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;
-- 
2.26.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]