Skip to content

Instantly share code, notes, and snippets.

@spchamp
Created October 30, 2016 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spchamp/aed53ad4e1d04b80ebfd588c638b049c to your computer and use it in GitHub Desktop.
Save spchamp/aed53ad4e1d04b80ebfd588c638b049c to your computer and use it in GitHub Desktop.
PDF generator for manual pages in *ROFF format. runtime-depends on ports textproc/groff and print/ghostscript9-base. Public domain. No warranty.
#!/bin/sh
THIS="$(basename $(readlink -f $0))"
msg() {
echo "$THIS: $@"
}
ferr() {
msg $@ 1>&2
exit 1
}
if [ -z "$1" ]; then
ferr "no query specified"
fi
if [ -n "$2" ]
then
OUTF="$1.$2.pdf"
QUERY="$2 $1"
NAME="$1($2)"
else
OUTF="$1.pdf"
QUERY="$1"
NAME="$1(*)"
fi
ONOTIF="Generated file ${OUTF}"
msg "Querying for manual page ${NAME}"
MPATH="$(man -w ${QUERY} 2>/dev/null)"
if [ -n "$MPATH" ]; then
zcat "${MPATH}" |
groff -mandoc -T ps -dpaper=a4 -P-pa4 |
ps2pdf - "${OUTF}" && msg "$ONOTIF"
else
ferr "No manual page found: ${NAME}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment