Yet another way to read beautifully formatted man pages

May 14, '09 07:30:03AM

Contributed by: dgerrity

Many contributors have come up with ways to read man pages in a more usable format. However, using troff to produce PDFs takes time and I don't really like the output. There are also some excellent man page reading apps out there, but they require launching and browsing a list.

So I came up with a simple shell function to provide exceptionally fast lookups from the Apple Developer site's HTML man pages. That way, you get your nicely-formatted Darwin-specific man pages in a tab in your browser.

The function uses man -w to get the section number and then forms a URL which then gets launched. The web pages are organized by section, and so the URL is not straighforward. I'm new to sed, and my guess is that there are readers that can improve my regex. I've tested this with with a variety of commands, but certainly not exhaustively.

Drop this into your user's .bashrc file. You should also put it into .bash_profile if you maintain them separately -- my .bash_profile has a single line (source ~/.bashrc), so I only have to maintain one.

function wman() {
   url="man -w ${1} | sed 's#.*\(${1}.\)\([[:digit:]]\).*\$#http://developer.apple.com/documentation/Darwin/Reference/ManPages/man\2/\1\2.html#'"
   open `eval $url`
}
Thereafter, you can just type wman and the name of the command you want (e.g., wman rsync). If anyone knows how to automatically scroll the browser down to the horizontal rule, I'd love to know how. There are no named anchor points in the pages, so a # in the URL doesn't work.

[robg adds: Two previous hints on different ways to read man pages: as a PDF in Previewas ASCII, HTML, or PostScript. I tested the wman command in this hint, and it works as described.]

Comments (21)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20090511115821563