Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 46 lines (37 sloc) 1.13 KB
#!/usr/bin/env bash
#man -t ledger | ps2pdf - /tmp/man-ledger.pdf && open /tmp/man-ledger.pdf
MAN_ARGS=("$@")
IDENTIFIER="$(echo "${MAN_ARGS[@]}" | sed -e 's/ //g')"
PDF_FILENAME="man-${IDENTIFIER}.pdf"
PDF_TARGET="${TMPDIR}${PDF_FILENAME}"
if [[ -f "${PDF_TARGET}" ]]; then
open "${PDF_TARGET}"
exit 0
fi
MAN_PATH="$(command -v man)"
if [[ -z "${MAN_PATH}" ]]; then
>&2 echo "No man found, are manpages actually installed?"
exit 1
fi
PS2PDF_PATH="$(command -v ps2pdf)"
if [[ -z "${PS2PDF_PATH}" ]]; then
>&2 echo "No ps2pdf found, ensure that it is installed."
exit 2
fi
# ensure it exists first
MANPAGE_PATH="$("${MAN_PATH}" --path ${MAN_ARGS})"
manpath_path_exit=$?
if [[ $manpath_path_exit -ne 0 ]]; then
#>&2 echo "No manpage available for '${MAN_ARGS}'."
exit $manpath_path_exit
fi
# -t outputs postscript using groff, see `man man` for details.
# ps2pdf - - means convert stdin to pdf and output on stdout
"${MAN_PATH}" -t "${MAN_ARGS[@]}" | "${PS2PDF_PATH}" - - > "${PDF_TARGET}"
if [[ -f "${PDF_TARGET}" ]]; then
open "${PDF_TARGET}"
exit 0
else
>&2 echo "${PDF_TARGET} does not exist, something went wrong."
exit 4
fi