Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

View nicely formatted 'man' pages UNIX
If you'd like to read the "man" pages (UNIX manual pages) in PDF mode, here's how to do it.

The following shell script displays high quality man pages using Preview.app (or whichever PDF viewer the finder thinks to use):
#!/bin/tcsh
set m=`man -w $1`
set c=`grog $m`
$c | ps2pdf - /tmp/$1.pdf
open /tmp/$1.pdf
Save the script in your personal bin directory, e.g. ~/bin/superman. Set execute permissions: chmod +x ~/bin/superman. And then superman ls will present nicely typeset man pages.

NOTE: In order for this to work, You'll need ghostscript installed for ps2pdf.
    •    
  • Currently 2.33 / 5
  You rated: 1 / 5 (3 votes cast)
 
[5,976 views]  

View nicely formatted 'man' pages | 7 comments | Create New Account
Click here to return to the 'View nicely formatted 'man' pages' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Slightly improved
Authored by: owain_vaughan on May 15, '01 06:01:20AM

#!/bin/tcsh
if (! -e /tmp/$1.pdf) then
set m=`man -w $1` || exit
set c=`grog $m`
$c | ps2pdf - /tmp/$1.pdf
endif
open /tmp/$1.pdf

This way, the script exits nicely if the page doesn't exist, and
doesn't recreate the PDF file if it already exists in /tmp



[ Reply to This | # ]
Very much improved
Authored by: owain_vaughan on May 15, '01 06:37:29AM
#!/bin/sh

if [ $# -eq 2 ]; then
  m=`man -w $1 $2` || exit
  PAGE=`basename $m`
  PDF=/tmp/$PAGE.pdf
  if [ ! -e $PDF ]; then
    c=`grog $m`
    $c | ps2pdf - $PDF
  fi
  open $PDF 
else
  m=`man -w $1` || exit
  for x in $m; do
    PAGE=`basename $x`
    PDF=/tmp/$PAGE.pdf
    if [ ! -e $PDF ]; then
      c=`grog $x`
      $c | ps2pdf - $PDF
    fi
    open $PDF
  done
fi

Using this version you can use the standard BSD 'man' semantics for looking up man pages - ie.
% superman ls % superman open % superman 2 open

Where there are multiple matches - all matching pages are opened as PDF files. Again checks are made to stop duplicating already created pages, and to exit cleanly if there are no matches.

[ Reply to This | # ]
Very much improved & smaller
Authored by: owain_vaughan on May 18, '01 05:44:45AM
Just in case everybody isn't bored by this already - this is the version I now use. It's pretty much identical to the previous one, but redundant variables are removed and therefore the new one-line 'if' blocks can be compressed onto one line....
#!/bin/sh
if [ $# -eq 2 ]; then
m=`man -w $1 $2` || exit
PDF=/tmp/`basename $m`.pdf
[ ! -e $PDF ] && `grog $m` | ps2pdf - $PDF
open $PDF
else
m=`man -w $1` || exit
for x in $m; do
PDF=/tmp/`basename $x`.pdf
[ ! -e $PDF ] && `grog $x` | ps2pdf - $PDF
open $PDF
done
fi
Simple eh? :)

[ Reply to This | # ]
Unpacking Ghostcript
Authored by: babbage on May 15, '01 10:04:46AM
...you seem to need to unpack GhostScript from your root ("/") directory, because it wants to put everything in your /usr/local/bin and /usr/local/share directories. If you unpack it from your home directory (or anywhere but / for that matter), it will create these underneath your current working directory. This is almost definitely not what you want to do. Do something like:
wget http://www.uoregon.edu/~koch/texshop/texshopold/gs.tar.gz
sudo mv gs.tar.gz /
cd /
sudo tar xzvf gs.tar.gz
rehash


[ Reply to This | # ]
View nicely formatted 'man' pages
Authored by: andyinindy on Oct 04, '04 02:26:33PM
You can also do this without ps2pdf using this Applescript:

tell application "Finder"
	activate
	display dialog "Please enter the terminal command name for which you would like a PDF-formatted man page:" default answer ""
	set commandName to the text returned of the result
end tell
set myGrog to (do shell script "man -w " & commandName)
set myGroff to (do shell script "grog " & myGrog)
do shell script myGroff & " > /Users/andy/Desktop/" & commandName & ".ps"
do shell script "open /Users/andy/Desktop/" & commandName & ".ps"
</code></pre>


[ Reply to This | # ]
View nicely formatted 'man' pages
Authored by: andyinindy on Oct 04, '04 02:27:54PM

minus the </code> and </pre> tags... why did those get posted??



[ Reply to This | # ]
View nicely formatted 'man' pages
Authored by: andyinindy on Oct 04, '04 02:31:47PM
Oh, and here's the script without the /Users/andy part (so it'll work on your system):

tell application "Finder"
	activate
	display dialog "Please enter the terminal command name for which you would like a PDF-formatted man page:" default answer ""
	set commandName to the text returned of the result
end tell
set myGrog to (do shell script "man -w " & commandName)
set myGroff to (do shell script "grog " & myGrog)
do shell script myGroff & " > $HOME/Desktop/" & commandName & ".ps"
do shell script "open $HOME/Desktop/" & commandName & ".ps"


[ Reply to This | # ]