From: Andre Noll Date: Sun, 15 Oct 2023 19:44:49 +0000 (+0200) Subject: Merge topic branch t/gui into pu X-Git-Url: http://git.tuebingen.mpg.de/?a=commitdiff_plain;ds=sidebyside;h=refs%2Fheads%2Fpu;hp=79113217e28306305622062b9f0c70b0a1a18148;p=gsu.git Merge topic branch t/gui into pu Started on 2023-08-22 * refs/heads/t/gui: gui: Remember menu position. --- diff --git a/subcommand b/subcommand index e5c0001..d37481c 100644 --- a/subcommand +++ b/subcommand @@ -168,20 +168,25 @@ gsu_getopts() _gsu_print_available_commands() { local cmd cmds - local -i count=0 + local -i maxlen=0 cols width=80 count=0 + result=$(stty size 2>/dev/null) + if (($? == 0)); then + gsu_is_a_number "${result#* }" + ((ret >= 0)) && ((result > 0)) && width=$result + fi _gsu_available_commands - cmds="$result" - printf 'Available commands:\n' + cmds=$result + for cmd in $cmds; do + ((${#cmd} > maxlen)) && maxlen=${#cmd} + done + let maxlen++ + ((width < maxlen)) && cols=1 || cols=$((width / maxlen)) + printf 'Available commands:' for cmd in $cmds; do - printf '%s' "$cmd" + ((count % cols == 0)) && printf '\n' + printf '%-*s' $maxlen $cmd let ++count - if ((count % 4)); then - printf '\t' - ((${#cmd} < 8)) && printf '\t' - else - printf '\n' - fi done printf '\n' } @@ -679,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'