In most cases, the user does not want to see the four subcommands
which are auto-generated by gsu, so omit them from the default output
and provide -a to show them anyway.
This patch has been languishing in a development branch for several
years, so it's kind of well tested.
+declare -A _gsu_help_text=() # indexed by autocmd
+_gsu_help_text['prefs']='
Print the current preferences.
Usage: prefs [-e]
Print the current preferences.
Usage: prefs [-e]
If -e is given, the config file is opened with the default editor.
Without options, the command prints out a list of all config variables,
together with their current value and the default value.
If -e is given, the config file is opened with the default editor.
Without options, the command prints out a list of all config variables,
together with their current value and the default value.
[[ "$result" == 'm' ]] && printf 'roff\ntext\nhtml\n'
}
[[ "$result" == 'm' ]] && printf 'roff\ntext\nhtml\n'
}
Print the manual.
Usage: man [-m <mode>] [-b <browser>]
Print the manual.
Usage: man [-m <mode>] [-b <browser>]
- local cmd="$1" help_txt="$2"
- {
- printf 'com_%s()\n' "$cmd"
- sed -e 's/^/## /g' <<< "$help_txt"
- } | _gsu_roffify_cmds
+ for cmd in "${!_gsu_help_text[@]}"; do
+ help_txt="${_gsu_help_text["$cmd"]}"
+ {
+ printf 'com_%s()\n' "$cmd"
+ sed -e 's/^/## /g' <<< "$help_txt"
+ } | _gsu_roffify_cmds
+ done
printf '\n.SH "GENERIC SUBCOMMANDS"\n'
printf 'The following commands are automatically created by gsu\n'
printf '\n.SH "GENERIC SUBCOMMANDS"\n'
printf 'The following commands are automatically created by gsu\n'
- _gsu_roffify_autocmd "help" "$_gsu_help_txt"
- _gsu_roffify_autocmd "man" "$_gsu_man_txt"
- _gsu_roffify_autocmd "prefs" "$_gsu_prefs_txt"
- _gsu_roffify_autocmd "complete" "$_gsu_complete_txt"
printf '\n.SH "LIST OF SUBCOMMANDS"\n'
printf 'Each command has its own set of options as described below.\n'
printf '\n.SH "LIST OF SUBCOMMANDS"\n'
printf 'Each command has its own set of options as described below.\n'
+_gsu_help_text['help']='
+Usage: help [-a] [command]
Without arguments, print the list of available commands. Otherwise,
Without arguments, print the list of available commands. Otherwise,
-print the help text for the given command."
+print the help text for the given command.
+
+-a: Also show the help of automatic commands. Ignored if a command
+is given.'
+_gsu_help_text['complete']='
Command line completion.
Usage: complete [<cword> <word>...]
Command line completion.
Usage: complete [<cword> <word>...]
If at least one argument is given, all possible completions are
written to stdout. This can be used from the completion function of
the subcommand.
If at least one argument is given, all possible completions are
written to stdout. This can be used from the completion function of
the subcommand.
+ local ere tab=' ' txt
+
+ gsu_getopts "$com_help_options"
+ eval "$result"
+ ((ret < 0)) && return
_gsu_get_command_regex
ere="$result"
_gsu_get_command_regex
ere="$result"
gsu_short_msg "### $gsu_name -- $gsu_banner_txt ###"
_gsu_usage 2>&1
{
gsu_short_msg "### $gsu_name -- $gsu_banner_txt ###"
_gsu_usage 2>&1
{
- printf "com_help()\n%s" "$_gsu_help_txt" | head -n 4; echo "--"
- printf "com_man()\n%s" "$_gsu_man_txt" | head -n 4; echo "--"
- printf "com_prefs()\n%s" "$_gsu_prefs_txt" | head -n 4; echo "--"
- printf "com_complete()\n%s" "$_gsu_complete_txt" | head -n 4; echo "--"
+ if [[ "$o_a" == 'true' ]]; then
+ _gsu_mfcb() { printf '%s\n' "$2"; }
+ for cmd in "${!_gsu_help_text[@]}"; do
+ printf "com_%s()" "$cmd"
+ txt="${_gsu_help_text["$cmd"]}"
+ mapfile -n 3 -c 1 -C _gsu_mfcb <<< "$txt"
+ printf -- '--\n'
+ done
+ fi
grep -EA 2 "$ere" "$0"
} | grep -v -- '--' \
| sed -En "/$ere/"'!d
grep -EA 2 "$ere" "$0"
} | grep -v -- '--' \
| sed -En "/$ere/"'!d
# and print the sucker
p'
# and print the sucker
p'
- echo
- echo "# Try $gsu_name help <command> for info on <command>."
+ printf "\n# Try %s help <command> for info on <command>, or %s help -a to see\n" \
+ "$gsu_name" "$gsu_name"
+ printf '# also the subcommands which are automatically generated by gsu.\n'
ret=$GSU_SUCCESS
return
fi
ret=$GSU_SUCCESS
return
fi
- if test "$1" = "help"; then
- echo "$_gsu_help_txt"
+ for cmd in "${!_gsu_help_text[@]}"; do
+ [[ "$1" != "$cmd" ]] && continue
+ printf '%s\n' "${_gsu_help_text["$cmd"]}"
- fi
- if test "$1" = "man"; then
- echo "$_gsu_man_txt"
- ret=$GSU_SUCCESS
- return
- fi
- if test "$1" = "prefs"; then
- echo "$_gsu_prefs_txt"
- ret=$GSU_SUCCESS
- return
- fi
- if test "$1" = "complete"; then
- echo "$_gsu_complete_txt"
- ret=$GSU_SUCCESS
- return
- fi
- ret=$GSU_SUCCESS
_gsu_get_command_regex "$1"
ere="$result"
if ! grep -Eq "$ere" "$0"; then
_gsu_get_command_regex "$1"
ere="$result"
if ! grep -Eq "$ere" "$0"; then