summaryrefslogtreecommitdiffstats
path: root/text-utils/column.c
diff options
context:
space:
mode:
authorKarel Zak2017-11-13 14:17:23 +0100
committerKarel Zak2017-11-13 14:17:23 +0100
commitb5de9e6942e62d2713b7667af8b46a471a29b43a (patch)
tree194e69673b648c72effe6af05f85abb983b4e41b /text-utils/column.c
parentcolumn: add --table-noheadings (diff)
downloadkernel-qcow2-util-linux-b5de9e6942e62d2713b7667af8b46a471a29b43a.tar.gz
kernel-qcow2-util-linux-b5de9e6942e62d2713b7667af8b46a471a29b43a.tar.xz
kernel-qcow2-util-linux-b5de9e6942e62d2713b7667af8b46a471a29b43a.zip
column: allow to hide unnamed columns
Addresses: https://github.com/karelzak/util-linux/pull/327 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'text-utils/column.c')
-rw-r--r--text-utils/column.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/text-utils/column.c b/text-utils/column.c
index 0a17c69cb..ad6c2b20e 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -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)