diff options
-rwxr-xr-x | tools/tool2man.sh | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/tool2man.sh b/tools/tool2man.sh new file mode 100755 index 0000000..82e4807 --- /dev/null +++ b/tools/tool2man.sh @@ -0,0 +1,52 @@ +#!/bin/sh -e +# Convert 'contrib' scripts to manual pages. + +# This script basically converts some of the comments inside scripts to manual +# page format. The intention behind this utility is to generate manual pages for +# contrib scripts without much hassle. + +case "$1" in + --help|-h|'') + printf 'usage: %s [file]\n' "${0##*/}" >&2 + exit 1 +esac + +out() { printf '%s\n' "$@"; } + +file=$1 +filename=${file##*/} +date=$(date "+%b %d, %Y") +docstr=$(sed -n '2s/# //p' $file) + +out \ + ".Dd $date" \ + ".Dt $filename 1" \ + ".Sh NAME" \ + ".Nm $filename" \ + ".Nd $docstr" + +while read -r line; do + case $line in + '###'*:) + line=${line%:} + out ".Ss ${line#'### '}" + ;; + '##'*:) + line=${line%:} + out ".Sh ${line#'## '}" + ;; + '##'|'###') + out ".Pp" + ;; + '##'*) + line=${line#'##'} + line=${line#'#'} + line=${line# } + out "$line" + ;; + esac +done < "$file" + +out ".Sh AUTHOR" ".An Cem Keylan Aq Mt cem@ckyln.com" +out ".Sh LICENSE" "See LICENSE for copyright information." +out ".Sh SEE ALSO" ".Xr cpt 1" |