|
|
10.4: Use Preview to view formatted man pages
I modified the scripts and suggestions to save the converted PDF in the caches directory, and to check there first. If the file exists, it is opened instead of converting another:
#!/bin/bash
#
# Opens man pages in Preview.
#
# The '-t' option to 'man' generates PostScript, which
# Preview can open. However, Preview needs to first
# convert to PDF, which can take a while. Hence, we
# save generated pages in a cache directory, and look
# there first. Also, this allows us to save the page
# with the 'man' entry as its name, which causes the
# Preview window to have that title.
#
if [ $# -eq 0 ]; then
X=$(basename "$0")
echo "$X: opens man pages in Preview"
echo "Usage: $X man parameters"
exit 1
fi
# Cache directory. Change to taste.
cachdir="${HOME}/Library/Caches/manpages"
# man page is last parameter, which is tricky to get
eval man=$$#
# file to save man page as PDF
manfile="${cachdir}/${man}"
# Create cache directory for 'man' output
mkdir -p "$cachdir"
# If desired PDF man page is in cache, open it
if [ -f "$manfile" ]; then
open -a Preview "$manfile"
else
# Invoke 'man' to check if man page exists, and if so,
# invoke man to format it to PS, pipe PS output to pstopdf,
# save result in cache
man -w $* >/dev/null
if [ $? -eq 0 ]; then
man -t $* | pstopdf -o "$manfile" -i
open -a Preview "$manfile"
fi
fi
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.06 seconds |
|