]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
column: add -1 placeholder to address last visible column
authorKarel Zak <kzak@redhat.com>
Wed, 8 Jun 2022 09:28:02 +0000 (11:28 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 8 Jun 2022 09:28:02 +0000 (11:28 +0200)
Addresses: https://github.com/util-linux/util-linux/issues/1700
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/column.1.adoc
text-utils/column.c

index 6da1dccfee774334c75b5ef0629b2dba74568788..99559ac46b2973fa351a1b1a273073d02f1b1e4d 100644 (file)
@@ -69,7 +69,7 @@ The argument _columns_ for *--table-** options is a comma separated list of the
 column names as defined by *--table-columns*, or names defined by
 *--table-column* or it's column number in order as specified by input. It's
 possible to mix names and numbers. The special placeholder '0' (e.g. -R0) may
-be used to specify all columns.
+be used to specify all columns and '-1' (e.g. -R -1) to specify the last visible column.
 
 *-J, --json*::
 Use JSON output format to print the table, the option *--table-columns* is required and the option *--table-name* is recommended.
index 245c2dd8d6f7ce6073a4d0cd9d7643504f72953a..d8eae9ee5942a034643eabb76570891b83c147f8 100644 (file)
@@ -251,23 +251,6 @@ static void init_table(struct column_control *ctl)
 
 }
 
-static struct libscols_column *string_to_column(struct column_control *ctl, const char *str)
-{
-       struct libscols_column *cl;
-
-       if (isdigit_string(str)) {
-               uint32_t n = strtou32_or_err(str, _("failed to parse column")) - 1;
-
-               cl = scols_table_get_column(ctl->tab, n);
-       } else
-               cl = scols_table_get_column_by_name(ctl->tab, str);
-
-       if (!cl)
-               errx(EXIT_FAILURE, _("undefined column name '%s'"), str);
-
-       return cl;
-}
-
 static struct libscols_column *get_last_visible_column(struct column_control *ctl)
 {
        struct libscols_iter *itr;
@@ -287,6 +270,25 @@ static struct libscols_column *get_last_visible_column(struct column_control *ct
        return last;
 }
 
+static struct libscols_column *string_to_column(struct column_control *ctl, const char *str)
+{
+       struct libscols_column *cl;
+
+       if (isdigit_string(str)) {
+               uint32_t n = strtou32_or_err(str, _("failed to parse column")) - 1;
+
+               cl = scols_table_get_column(ctl->tab, n);
+       } else if (strcmp(str, "-1") == 0)
+               cl = get_last_visible_column(ctl);
+       else
+               cl = scols_table_get_column_by_name(ctl->tab, str);
+
+       if (!cl)
+               errx(EXIT_FAILURE, _("undefined column name '%s'"), str);
+
+       return cl;
+}
+
 static int column_set_flag(struct libscols_column *cl, int fl)
 {
        int cur = scols_column_get_flags(cl);