From 241af60a8f3df56c18fb13b0cb22df23297b2538 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 2 Aug 2023 23:09:11 +0200 Subject: [PATCH] com_help(): Improve formating of command/description list The help output, which consists of the subcommand name and the one-line description, is formatted incorrectly if the name of one or more subcommands exceeds 16 characters. Pre-compute the maximal length of the command names upfront to fix that. --- subcommand | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/subcommand b/subcommand index 817486d..d37481c 100644 --- a/subcommand +++ b/subcommand @@ -684,7 +684,21 @@ com_help() y/\n/'"$tab"'/ # and print the sucker - p' + p + ' | { + local -a cmds=() descs=() + local -i i maxlen=1 + local cmd desc + while read cmd desc; do + ((maxlen < ${#cmd})) && maxlen=${#cmd} + cmds[${#cmds[@]}]=$cmd + descs[${#descs[@]}]=$desc + done + for ((i = 0; i < ${#cmds[@]}; i++)); do + printf '%-*s %s\n' $maxlen ${cmds[$i]} \ + "${descs[$i]}" + done + } printf "\n# Try %s help for info on , or %s help -a to see\n" \ "$gsu_name" "$gsu_name" printf '# also the subcommands which are automatically generated by gsu.\n' -- 2.39.2