coreutils
[Top][All Lists]
Advanced

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

[PATCH] :Adding a --terse option, by request of Bruce Dubbs


From: Ed Neville
Subject: [PATCH] :Adding a --terse option, by request of Bruce Dubbs
Date: Sat, 16 Mar 2019 19:18:06 +0000
User-agent: Mutt/1.5.23 (2014-03-12)

A --terse option:

  $ df -k --terse --output=used $PWD

Should output a single integer if the path exists.

---
 src/df.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/df.c b/src/df.c
index 041f2820d..c785ec6ec 100644
--- a/src/df.c
+++ b/src/df.c
@@ -85,6 +85,9 @@ static bool file_systems_processed;
    SunOS 4.1.3, for one.  It is *not* necessary on GNU/Linux.  */
 static bool require_sync;
 
+/* If true we omit the header from output */
+static bool terse_option;
+
 /* Desired exit status.  */
 static int exit_status;
 
@@ -250,7 +253,8 @@ enum
   NO_SYNC_OPTION = CHAR_MAX + 1,
   SYNC_OPTION,
   TOTAL_OPTION,
-  OUTPUT_OPTION
+  OUTPUT_OPTION,
+  TERSE_OPTION
 };
 
 static struct option const long_options[] =
@@ -266,6 +270,7 @@ static struct option const long_options[] =
   {"print-type", no_argument, NULL, 'T'},
   {"sync", no_argument, NULL, SYNC_OPTION},
   {"no-sync", no_argument, NULL, NO_SYNC_OPTION},
+  {"terse", no_argument, NULL, TERSE_OPTION},
   {"total", no_argument, NULL, TOTAL_OPTION},
   {"type", required_argument, NULL, 't'},
   {"exclude-type", required_argument, NULL, 'x'},
@@ -554,6 +559,9 @@ get_header (void)
 {
   size_t col;
 
+  if( terse_option )
+    return;
+
   alloc_table_row ();
 
   for (col = 0; col < ncolumns; col++)
@@ -1539,6 +1547,7 @@ or all file systems by default.\n\
       --sync            invoke sync before getting usage info\n\
 "), stdout);
       fputs (_("\
+      --terse           do not print column headers\n\
       --total           elide all entries insignificant to available space,\n\
                           and produce a grand total\n\
 "), stdout);
@@ -1581,6 +1590,7 @@ main (int argc, char **argv)
   show_listed_fs = false;
   human_output_opts = -1;
   print_type = false;
+  terse_option = false;
   file_systems_processed = false;
   exit_status = EXIT_SUCCESS;
   print_grand_total = false;
@@ -1700,6 +1710,10 @@ main (int argc, char **argv)
           print_grand_total = true;
           break;
 
+        case TERSE_OPTION:
+          terse_option = true;
+          break;
+
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
 
-- 
2.11.0




reply via email to

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