#!/bin/ksh # # scripthelp provides a nifty way to provide help and documentation for # scripts with a minimum of effort by just using selected comments as # help-text. Comment the script as usual. Whenever you want something to # to be displayed as help, start a comment with #h instead of # # # the resulting help can be more than a page long as it is displayed in a pager # (with a fancy prompt if "less" is available"). # # usage: scripthelp $0 # # Platforms: Linux or SCO OSR5 # For an example, see my scripts: publishme, asciichart, trimman # # Brian K. White - linut@squonk.net strip_h () { awk '/#h/ { if ($0 ~ /^#h/) sub("#h","") ; sub("#h","#") ; print $0 }' $1 } less >/dev/null 2>&1 && { strip_h $1 |less -irqn -Ps" `basename $1` help ?e(Bottom):?s (%pm\%) : .. [Q]=quit [/]=search [arrows/page]=scroll " } || { strip_h $1 |${PAGER:-more} } # Here is a version of scripthelp that may be pasted right into a script so # that the script is self-sufficient (better for distributing). Use this (long) # line in place of "scripthelp $0" # awk '/#h/ { if ($0 ~ /awkavoid/) next ; if ($0 ~ /^#h/) sub("#h","") ; sub("#h","#") ; print $0 }' $0 |less -irqn -Ps" `basename $0` help ?e(Bottom):?s (%pm\%) : .. [Q]=quit [/]=search [arrows/page]=scroll "