Skip to content

Instantly share code, notes, and snippets.

@averyrobinson
Created January 14, 2015 23:03
Show Gist options
  • Save averyrobinson/8d5d6f95d477712102b3 to your computer and use it in GitHub Desktop.
Save averyrobinson/8d5d6f95d477712102b3 to your computer and use it in GitHub Desktop.
pman
#!/bin/bash
# pman -- view a typeset man page
PATH=/bin:/usr/bin:/usr/local/bin
cachedir=/tmp/${USER}/pman-cache/
# display error if no arguments
if [[ $# -eq 0 ]]
then
echo "What manual page do you want?"
exit 1
fi
# create cache directory if necessary
if [[ ! -d ${cachedir} ]]
then
mkdir -p ${cachedir}
fi
# name cache file
command="$*"
source=$(man -w ${command})
target=${cachedir}/${command// /-}.pdf
# typeset and cache man page if it doesn't yet exist, or is out of date
if [[ ! -f ${target} || ${source} -nt ${target} ]]
then
man -t "$@" | ps2pdf - ${target}
fi
# view cached man page
evince ${target} &> /dev/null &
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment