Add PDF export of Man pages in OS X
Submitted by tlarkin on Sat, 08/30/2008 - 15:14
So, if you use Unix or a variant like Linux you are familiar with the command line. Which means that you have probably sifted through the man pages (manual) of several commands in the past. A lot of times it gets fruturating or annoying having to refer to a man page or to have multiple terminal windows open just to be able to read the command's manual. So, there are two solutions I can suggest to remedy this. The first one is a free third party applicaiton that will open up all man pages in a web browser. This will allow you to keep the manual open in a web browser while you test out commands or write a script. Bwana can be found here:
http://www.bruji.com/bwana/
The second is to modify your ~/.bash_profile in OS X. You should always just modify your specific user's .bash_profile, that way if anything botches it only affects that user account and no one else. To do this simply open up terminal and make sure you are in ~/ and type ls -al. If you don't see your .bash_profile, simply type this command, touch .bash_profile. Now you should see it listed. Now that you can see it, type in pico .bash_profile and copy and paste this text into the terminal.
Since this is much more "pretty" than the standard man page I named the function woman instead. Save out of pico and over write the file. Now that it is in place quit and restart terminal. Now any time you wish to export the man pages of any command to a nice PDF file, just type in woman <command>, or for example: woman grep. Now watch it open up in a nice PDF. The first time you run this funciton it will have to load the library of fonts and text but that only happens on the very first run.
Enjoy
function woman { tmpfile="/tmp/man ${*}.pdf" if [ \! -f "${tmpfile}" ] then man -t "${*}" | pstopdf -i -o "${tmpfile}" fi open "${tmpfile}" }
- Login to post comments

Comments
Man2Pdf
Cool, thanks for sharing!
Thanks
thanks for your input, your script looks nice. If I get time I would love to test it out. Thanks for visiting my site and taking the time to add this, I appreciate it. -Tom
Man pages in the browser
Hi
woman - such a cool name. Great idea!
I have a script 'manp' (man print) which does almost the same thing that you do. The PDF pages are beautiful. However it's a pity that Preview isn't a tabbed application - you can end up with lots of windows. So I'm more enthusiastic about my script 'many' which uses man2html (a perl script) to display the man pages in Safari.
Oh, and it also looks in the perldocs and pydoc if it doesn't find a man page.
[code]
#!/bin/csh
#
# set up a temporary directory if necessary
if ( ! -e ~/temp ) then
mkdir -f ~/temp
endif
#
# kill the old txt and html files
set f=~/temp/$argv[$#argv].txt
set h=~/temp/$argv[$#argv].html
rm -rf $f $h
#
# is there a file called ~/bin/man.html
set m=~/bin/man$argv[$#argv].html
if ( ! -e $m ) then
# write out a few blank lines (otherwise man2html gets a little confused!)
foreach i ( a b c d e f g h i j k l m )
echo >> $f
end
# get the man page
man $* >> $f
set s = $status
# if it failed, ask perldoc if he knows about it!
if ( $s ) then
perldoc $* >> $f
set s = $status
endif
# if it failed, ask pydoc if he knows about it!
if ( $s ) then
pydoc $* >> $f
set s = $status
endif
#
# if we've found it, format and display
if ( ! $s ) then
man2html -compress < $f > $h && open $h
endif
else
cp $m $h
open $h
endif
[/code]