diff options
author | Karel Zak | 2015-12-10 13:03:46 +0100 |
---|---|---|
committer | Karel Zak | 2015-12-10 13:03:46 +0100 |
commit | a6dc8dcd028dbbec9562fd09921055e856392b7d (patch) | |
tree | d58e04ea21d9757d6e52149ed2fae83f5e462f8a | |
parent | libsmartcols: add SCOLS_FL_HIDDEN (diff) | |
download | kernel-qcow2-util-linux-a6dc8dcd028dbbec9562fd09921055e856392b7d.tar.gz kernel-qcow2-util-linux-a6dc8dcd028dbbec9562fd09921055e856392b7d.tar.xz kernel-qcow2-util-linux-a6dc8dcd028dbbec9562fd09921055e856392b7d.zip |
lsblk: allow to --sort by hidden column
For example:
lsblk -o NAME --sort SIZE
prints NAMEs, but sort by SIZEs.
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | Documentation/TODO | 7 | ||||
-rw-r--r-- | misc-utils/lsblk.c | 10 |
2 files changed, 8 insertions, 9 deletions
diff --git a/Documentation/TODO b/Documentation/TODO index 22fa0e06f..9bd0134e7 100644 --- a/Documentation/TODO +++ b/Documentation/TODO @@ -64,13 +64,6 @@ libmount (mount/umount) (all this already supported by libmount) -libsmartcols ------------ - - - (!) add SCOLS_FL_HIDDEN flag to make it possible to hide a column. Then we - can use such column in lsblk(8) to only sort lines, but do not print the column. - - lsblk -o NAME --sort SIZE partx ----- diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 2604e84c2..fff1584d3 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -214,6 +214,7 @@ struct lsblk { unsigned int nodeps:1; /* don't print slaves/holders */ unsigned int scsi:1; /* print only device with HCTL (SCSI) */ unsigned int paths:1; /* print devnames with "/dev" prefix */ + unsigned int sort_hidden:1; /* sort column not between output columns */ }; struct lsblk *lsblk; /* global handler */ @@ -1849,8 +1850,11 @@ int main(int argc, char *argv[]) if (nexcludes == 0 && nincludes == 0) excludes[nexcludes++] = 1; /* default: ignore RAM disks */ - if (lsblk->sort_id >= 0 && column_id_to_number(lsblk->sort_id) < 0) - errx(EXIT_FAILURE, _("the sort column has to be among the output columns")); + if (lsblk->sort_id >= 0 && column_id_to_number(lsblk->sort_id) < 0) { + /* the sort column is not between output columns -- add as hidden */ + add_column(columns, ncolumns++, lsblk->sort_id); + lsblk->sort_hidden = 1; + } mnt_init_debug(0); scols_init_debug(0); @@ -1876,6 +1880,8 @@ int main(int argc, char *argv[]) if (!(scols_flags & LSBLK_TREE) && id == COL_NAME) fl &= ~SCOLS_FL_TREE; + if (lsblk->sort_hidden && lsblk->sort_id == id) + fl |= SCOLS_FL_HIDDEN; cl = scols_table_new_column(lsblk->table, ci->name, ci->whint, fl); if (!cl) { |