]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
column: allow to hide unnamed columns
authorKarel Zak <kzak@redhat.com>
Mon, 13 Nov 2017 13:17:23 +0000 (14:17 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 13 Nov 2017 13:17:23 +0000 (14:17 +0100)
Addresses: https://github.com/karelzak/util-linux/pull/327
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/column.1
text-utils/column.c

index 3bcd0f086e59cc16cf954e3e0245d9674f09dc2a..2bc47edde23a19d85b991d9f7fdf3d35a76f4e4e 100644 (file)
@@ -100,7 +100,8 @@ Print header line for each page.
 Specify columns where is possible to use multi-line cell for long text when
 necessary.
 .IP "\fB\-H, \-\-table-hide\fP \fIcolumns\fP"
-Don't print specified columns.
+Don't print specified columns. The special placeholder '-' maybe be used to
+hide all unnamed columns (see --table-columns).
 .IP "\fB\-O, \-\-table-order\fP \fIcolumns\fP"
 Specify columns order on output.
 .IP "\fB\-n, \-\-table-name\fP \fIname\fP"
@@ -127,6 +128,13 @@ Print fstab with header line and align number to the right:
 .EX
 \fBsed 's/#.*//' /etc/fstab | column --table --table-columns SOURCE,TARGET,TYPE,OPTIONS,PASS,FREQ --table-right PASS,FREQ\fR
 .EE
+.PP
+Print fstab and hide unnamed columns:
+.EX
+\fBsed 's/#.*//' /etc/fstab | column --table --table-columns SOURCE,TARGET,TYPE --table-hide -\fR
+.EE
+.PP
+
 .PP
 Print a tree:
 .EX
index 0a17c69cb98a4fd16d392055503b0efa501e3c5e..ad6c2b20e21e9135a0597bc8b5efb36d5b5bf328 100644 (file)
@@ -276,13 +276,38 @@ static void apply_columnflag_from_list(struct column_control *ctl, const char *l
 {
        char **all = split_or_error(list, errmsg);
        char **one;
+       int unnamed = 0;
 
        STRV_FOREACH(one, all) {
-               struct libscols_column *cl = string_to_column(ctl, *one);
+               struct libscols_column *cl;
+
+               if (flag == SCOLS_FL_HIDDEN && strcmp(*one, "-") == 0) {
+                       unnamed = 1;
+                       continue;
+               }
+               cl = string_to_column(ctl, *one);
                if (cl)
                        column_set_flag(cl, flag);
        }
        strv_free(all);
+
+       /* apply flag to all columns without name */
+       if (unnamed) {
+               struct libscols_iter *itr;
+               struct libscols_column *cl;
+
+               itr = scols_new_iter(SCOLS_ITER_FORWARD);
+               if (!itr)
+                       err_oom();
+
+               while (scols_table_next_column(ctl->tab, itr, &cl) == 0) {
+                       struct libscols_cell *ce = scols_column_get_header(cl);
+
+                       if (ce == NULL ||  scols_cell_get_data(ce) == NULL)
+                               column_set_flag(cl, flag);
+               }
+               scols_free_iter(itr);
+       }
 }
 
 static void reorder_table(struct column_control *ctl)