From: Andre Noll Date: Sun, 26 Aug 2007 21:07:14 +0000 (+0200) Subject: gsu: Make man a generic gsu command. X-Git-Url: http://git.tuebingen.mpg.de/?p=gsu.git;a=commitdiff_plain;h=9cb0e6abcd699f8a595f523099ac7ba0db77f76a;hp=59a73de1f5e84a87cd1889b50ea9a45c047e70c4 gsu: Make man a generic gsu command. Also, make the help text of eat grutatxt-friendly and add some more documentation. --- diff --git a/funcs/gsu b/funcs/gsu index c2304ca..dc2033d 100644 --- a/funcs/gsu +++ b/funcs/gsu @@ -95,6 +95,82 @@ gsu_usage() } export -f gsu_usage +gsu_available_commands() +{ + result="$( (printf "help\nman\n"; grep "^com_[a-z_]\+()" $0) \ + | sed -e 's/^com_//' -e 's/()//' \ + | sort \ + | tr '\n' ' ')" + ret=$GSU_SUCCESS +} +export -f gsu_available_commands + +gsu_print_available_commands() +{( + local i count + gsu_short_msg "Available commands:" + for i in $gsu_cmds; do + printf "$i" + count=$(($count + 1)) + if test $(($count % 4)) -eq 0; then + echo + else + printf "\t" + if test ${#i} -lt 8; then + printf "\t" + fi + fi + done + echo +) 2>&1 +} +export -f gsu_print_available_commands + +export gsu_man_txt=" +Print the manual. + +Usage: man" + +com_man() +{ + local equal_signs="==================================================" + local minus_signs="--------------------------------------------------" + local tilde_signs="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + local com num + + echo "$gsu_self (_${gsu_banner_txt}_) manual" + echo "${equal_signs:0:${#gsu_self} + ${#gsu_banner_txt} + 16}" + echo + + sed -e '1,/^#\{70,\}/d' -e '/^#\{70,\}/,$d' $0 -e 's/^# *//' + echo "----" + echo + echo "$gsu_self usage" + echo "${minus_signs:0:${#gsu_self} + 6}" + printf "\t" + gsu_usage 2>&1 + echo "Each command has its own set of options as described below." + echo + echo "----" + echo + echo "Available commands:" + + gsu_available_commands + for com in $result; do + num=${#com} + if test $num -lt 4; then + num=4 + fi + echo "${minus_signs:0:$num}" + echo "$com" + echo "${minus_signs:0:$num}" + $0 help $com + echo + done + ret=$GSU_SUCCESS +} +export -f com_man + export gsu_help_txt=" Print online help. @@ -102,14 +178,18 @@ Usage: help [command] Without arguments, print the list of available commands. Otherwise, print the help text for the given command." + com_help() { local a b if test -z "$1"; then - gsu_banner_msg - gsu_usage + gsu_banner_msg 2>&1 + gsu_usage 2>&1 # sed is magic, baby - grep -A 2 "^com_\([a-zA-Z_0-9]\+\)()" $0 \ + (printf "com_help()\n$gsu_help_txt" | head -n 4; echo "--" + printf "com_man()\n$gsu_man_txt" | head -n 4; echo "--" + + grep -A 2 "^com_\([a-zA-Z_0-9]\+\)()" $0) \ | grep -v -- '--' \ | sed -e '/^com_\([a-zA-Z_0-9]\+\)()/bs' \ -e 'H;$!d;x;s/\n//g;b' \ @@ -125,12 +205,17 @@ com_help() echo "$b" done echo - gsu_msg "Try $gsu_self help for info on ." + echo "Try $gsu_self help for info on ." ret=$GSU_SUCCESS return fi if test "$1" = "help"; then - gsu_short_msg "$gsu_help_txt" + echo "$gsu_help_txt" + ret=$GSU_SUCCESS + return + fi + if test "$1" = "man"; then + echo "$gsu_man_txt" ret=$GSU_SUCCESS return fi @@ -145,37 +230,6 @@ com_help() } export -f com_help -gsu_available_commands() -{ - result="$( (echo help; grep "^com_[a-z_]\+()" $0) \ - | sed -e 's/^com_//' -e 's/()//' \ - | sort \ - | tr '\n' ' ')" - ret=$SUCCESS -} -export -f gsu_available_commands - -gsu_print_available_commands() -{( - local i count - gsu_short_msg "Available commands:" - for i in $gsu_cmds; do - printf "$i" - count=$(($count + 1)) - if test $(($count % 4)) -eq 0; then - echo - else - printf "\t" - if test ${#i} -lt 8; then - printf "\t" - fi - fi - done - echo -) 2>&1 -} -export -f gsu_print_available_commands - gsu() { local i