]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsmem: add column header annotations
authorChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Mon, 23 Mar 2026 02:56:56 +0000 (22:56 -0400)
committerChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Mon, 27 Apr 2026 14:37:15 +0000 (10:37 -0400)
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
bash-completion/lsmem
sys-utils/lsmem.1.adoc
sys-utils/lsmem.c

index 27793e743e7b58e45bda79ea80a54189d8bec3e9..484b557a352a847510f313a266b40c6e03f27e3a 100644 (file)
@@ -5,6 +5,10 @@ _lsmem_module()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"
        case $prev in
+               '--annotate')
+                       COMPREPLY=( $(compgen -W "always auto never" -- $cur) )
+                       return 0
+                       ;;
                '-o'|'--output')
                        local prefix realcur OUTPUT_ALL OUTPUT
                        realcur="${cur##*,}"
@@ -34,6 +38,7 @@ _lsmem_module()
                        ;;
        esac
        OPTS="
+               --annotate
                --json
                --pairs
                --all
index 26c330de7a084b25a7f9a498f3dc5b7f86716458..0c051b668ac3920c4738ca9462c5bc0c207a0c62 100644 (file)
@@ -97,6 +97,8 @@ Gather memory data for a Linux instance other than the instance from which the *
 *--summary*[**=**_when_]::
 This option controls summary lines output. The optional argument _when_ can be *never*, *always* or *only*. If the _when_ argument is omitted, it defaults to *only*. The summary output is suppressed for *--raw*, *--pairs*, and *--json*.
 
+include::man-common/annotate.adoc[]
+
 include::man-common/help-version.adoc[]
 
 == ENVIRONMENT
index 68b2d303620f93338ba9cd1014b4565d0d6f9e1b..007beaf6e0d1c614198947d5ad6754679ca25553 100644 (file)
@@ -95,7 +95,8 @@ struct lsmem {
                                split_by_memmap_on_memory : 1,
                                split_by_config : 1,
                                have_zones : 1,
-                               have_memconfig : 1;
+                               have_memconfig : 1,
+                               annotate_headers : 1;
 };
 
 
@@ -667,20 +668,21 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_("List the ranges of available memory with their online status.\n"), out);
 
        fputs(USAGE_OPTIONS, out);
-       fputs(_(" -J, --json           use JSON output format\n"), out);
-       fputs(_(" -P, --pairs          use key=\"value\" output format\n"), out);
-       fputs(_(" -a, --all            list each individual memory block\n"), out);
-       fputs(_(" -b, --bytes          print SIZE in bytes rather than in human readable format\n"), out);
-       fputs(_(" -n, --noheadings     don't print headings\n"), out);
-       fputs(_(" -o, --output <list>  output columns\n"), out);
-       fputs(_("     --output-all     output all columns\n"), out);
-       fputs(_(" -r, --raw            use raw output format\n"), out);
-       fputs(_(" -S, --split <list>   split ranges by specified columns\n"), out);
-       fputs(_(" -s, --sysroot <dir>  use the specified directory as system root\n"), out);
-       fputs(_("     --summary[=when] print summary information (never,always or only)\n"), out);
+       fputs(_(" -J, --json                use JSON output format\n"), out);
+       fputs(_(" -P, --pairs               use key=\"value\" output format\n"), out);
+       fputs(_(" -a, --all                 list each individual memory block\n"), out);
+       fputs(_(" -b, --bytes               print SIZE in bytes rather than in human readable format\n"), out);
+       fputs(_(" -n, --noheadings          don't print headings\n"), out);
+       fputs(_(" -o, --output <list>       output columns\n"), out);
+       fputs(_("     --output-all          output all columns\n"), out);
+       fputs(_(" -r, --raw                 use raw output format\n"), out);
+       fputs(_("     --annotate[=<when>]   annotate columns with a tooltip (always|never|auto)\n"), out);
+       fputs(_(" -S, --split <list>        split ranges by specified columns\n"), out);
+       fputs(_(" -s, --sysroot <dir>       use the specified directory as system root\n"), out);
+       fputs(_("     --summary[=when]      print summary information (never,always or only)\n"), out);
 
        fputs(USAGE_SEPARATOR, out);
-       fprintf(out, USAGE_HELP_OPTIONS(22));
+       fprintf(out, USAGE_HELP_OPTIONS(27));
 
        fputs(USAGE_COLUMNS, out);
        for (i = 0; i < ARRAY_SIZE(coldescs); i++)
@@ -698,13 +700,14 @@ int main(int argc, char **argv)
                        .want_summary = 1
                }, *lsmem = &_lsmem;
 
-       const char *outarg = NULL, *splitarg = NULL, *prefix = NULL;
+       const char *outarg = NULL, *splitarg = NULL, *prefix = NULL, *annotate_opt_arg = NULL;
        int c;
        size_t i;
 
        enum {
                LSMEM_OPT_SUMARRY = CHAR_MAX + 1,
-               OPT_OUTPUT_ALL
+               OPT_OUTPUT_ALL,
+               OPT_ANNOTATE,
        };
 
        static const struct option longopts[] = {
@@ -721,6 +724,7 @@ int main(int argc, char **argv)
                {"split",       required_argument,      NULL, 'S'},
                {"version",     no_argument,            NULL, 'V'},
                {"summary",     optional_argument,      NULL, LSMEM_OPT_SUMARRY },
+               { "annotate",   optional_argument, NULL, OPT_ANNOTATE },
                {NULL,          0,                      NULL, 0}
        };
        static const ul_excl_t excl[] = {       /* rows and cols in ASCII order */
@@ -787,7 +791,9 @@ int main(int argc, char **argv)
                        } else
                                lsmem->want_table = 0;
                        break;
-
+               case OPT_ANNOTATE:
+                       annotate_opt_arg = optarg;
+                       break;
                case 'h':
                        usage();
                case 'V':
@@ -802,6 +808,9 @@ int main(int argc, char **argv)
                errtryhelp(EXIT_FAILURE);
        }
 
+       if (annotationwanted(annotate_opt_arg))
+               lsmem->annotate_headers = 1;
+
        if (lsmem->want_table + lsmem->want_summary == 0)
                errx(EXIT_FAILURE, _("options --{raw,json,pairs} and --summary=only are mutually exclusive"));
 
@@ -893,6 +902,9 @@ int main(int argc, char **argv)
                                break;
                        }
                }
+
+               if (lsmem->annotate_headers && ci->help)
+                       scols_column_refer_annotation(cl, ci->help);
        }
 
        if (splitarg) {