]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: add column header annotations
authorChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Mon, 23 Mar 2026 02:30:15 +0000 (22:30 -0400)
committerChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Mon, 23 Mar 2026 02:30:15 +0000 (22:30 -0400)
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
bash-completion/lsblk
misc-utils/lsblk.8.adoc
misc-utils/lsblk.c
misc-utils/lsblk.h

index 577dcce13cfda08b035bcf2b162711f5f1d96d6e..3a94e3c2db8d6e892b1abca0a815cdaa2c386672 100644 (file)
@@ -64,6 +64,7 @@ _lsblk_module()
        case $cur in
                -*)
                        OPTS="--all
+                               --annotate
                                --bytes
                                --nodeps
                                --discard
index 3c873f0f359d4e0614758c8222b207fce5581ecf..8510f7ae3f09df9e844d045bc684d5aab9b3e7a4 100644 (file)
@@ -202,6 +202,8 @@ Reads data from a file. This method is only used if the --sysroot option is spec
 *none*;;
 Does not probe. This method always stops probing.
 
+include::man-common/annotate.adoc[]
+
 include::man-common/help-version.adoc[]
 
 == EXIT STATUS
index 6a8769bc7838124ee50ac20a2ff91f00018c46b5..c129c39b2cc4a218689a6137f442e76ddfeed56a 100644 (file)
@@ -2347,6 +2347,8 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -o, --output <list>  output columns (see --list-columns)\n"), out);
        fputs(_(" -p, --paths          print complete device path\n"), out);
        fputs(_(" -r, --raw            use raw output format\n"), out);
+       fputs(_("     --annotate[=<when>]\n"
+               "                      annotate columns with a tooltip (always|never|auto)\n"), out);
        fputs(_(" -s, --inverse        inverse dependencies\n"), out);
        fputs(_(" -t, --topology       output info about topology\n"), out);
        fputs(_(" -w, --width <num>    specifies output width as number of characters\n"), out);
@@ -2413,7 +2415,7 @@ int main(int argc, char *argv[])
        };
        struct lsblk_devtree *tr = NULL;
        int c, status = EXIT_FAILURE, collist = 0;
-       char *outarg = NULL;
+       char *outarg = NULL, *annotate_opt_arg = NULL;
        size_t i;
        unsigned int width = 0;
        int force_tree = 0, has_tree_col = 0;
@@ -2424,7 +2426,8 @@ int main(int argc, char *argv[])
                OPT_COUNTER,
                OPT_HIGHLIGHT,
                OPT_PROPERTIES_BY,
-               OPT_HYPERLINK
+               OPT_HYPERLINK,
+               OPT_ANNOTATE,
        };
 
        static const struct option longopts[] = {
@@ -2468,6 +2471,7 @@ int main(int argc, char *argv[])
                { "ct",         required_argument, NULL, OPT_COUNTER },
                { "properties-by", required_argument, NULL, OPT_PROPERTIES_BY },
                { "list-columns", no_argument,     NULL, 'H' },
+               { "annotate",   optional_argument, NULL, OPT_ANNOTATE },
                { NULL, 0, NULL, 0 },
        };
 
@@ -2689,6 +2693,9 @@ int main(int argc, char *argv[])
                        if (hyperlinkwanted(optarg))
                                lsblk->uri = xgethosturi(NULL);
                        break;
+               case OPT_ANNOTATE:
+                       annotate_opt_arg = optarg;
+                       break;
                case 'H':
                        collist = 1;
                        break;
@@ -2707,6 +2714,9 @@ int main(int argc, char *argv[])
        if (force_tree)
                lsblk->flags |= LSBLK_TREE;
 
+       if (annotationwanted(annotate_opt_arg))
+               lsblk->annotate_headers = true;
+
        check_sysdevblock();
 
        if (!ncolumns) {
@@ -2820,6 +2830,9 @@ int main(int argc, char *argv[])
                        scols_column_set_uri(cl, lsblk->uri);
 
                set_column_type(ci, cl, fl);
+
+               if (lsblk->annotate_headers && ci->help)
+                       scols_column_refer_annotation(cl, ci->help);
        }
 
        if (lsblk->filter)
index 90d2df1a135c10072a89caa7172b5518b368ef94..d9dbacdb7e7d2cc952680ab22decb2a838ae17d2 100644 (file)
@@ -79,6 +79,7 @@ struct lsblk {
        bool dedup_hidden;      /* deduplication column not between output columns */
        bool force_tree_order;  /* sort lines by parent->tree relation */
        bool noempty;           /* hide empty devices */
+       bool annotate_headers;  /* annotate column headers */
 };
 
 extern struct lsblk *lsblk;     /* global handler */