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

Open formatted man pages in Preview from the command line UNIX
I spend a lot of time reading man pages. Normally, the system pager less is fine for this. Occasionally, they're big enough or important enough that I want to keep them open in a window and read them at leisure. For those cases, I made a 2-line shell script pdfman.sh that runs man to generate postscript and presents the formatted output through preview.

Here is the script:
#!/bin/sh
ps=`mktemp -t manpageXXXX`.ps
man -t $@ > "$ps"
open "$ps"

[crarko adds: There are a number of ways to accomplish the viewing of man pages in Preview such as this older hint. The method can vary between versions of Mac OS X. The present hint is an addition to the list of methods.]
    •    
  • Currently 2.80 / 5
  You rated: 1 / 5 (5 votes cast)
 
[6,855 views]  

Open formatted man pages in Preview from the command line | 17 comments | Create New Account
Click here to return to the 'Open formatted man pages in Preview from the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Open formatted man pages in Preview from the command line
Authored by: SeanAhern on May 12, '11 08:41:05AM
No need to go through all that trouble with temporary files and all. This can be done in one line (which can then be made into an alias or function in your shell):
man -t function | ps2pdf - - | open -f -a Preview

See crarko's link for more examples that include caching and such.

[ Reply to This | # ]

Open formatted man pages in Preview from the command line
Authored by: broomdodger on May 12, '11 10:25:44AM

--OR--
If you would like to read man pages within vim, add the following to your .profile:

vman() { man "$@" | col -bx | iconv -c | vim -c "set ft=man nomod nolist" -; }



[ Reply to This | # ]
need to install ps2pdf
Authored by: kipkoan on May 12, '11 12:30:45PM
You will need to install "ps2pdf" for this to work, which is included with "ghostscript". I installed it using HomeBrew:

brew install ghostscript

[ Reply to This | # ]
need to install ps2pdf
Authored by: beepotato on May 15, '11 12:23:13AM

As shown a few comments further by bglnelissen, there is actually no need for ps2pdf. Preview handles the conversion from Postscript.



[ Reply to This | # ]
Open formatted man pages in Preview from the command line
Authored by: macintron on May 12, '11 09:15:52AM
Open formatted man pages in Preview from the command line
Authored by: Anonymous on May 12, '11 10:37:30AM

http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/index.html#//apple_ref/doc/uid/TP40000894

Or compile up an old version of xman.

And don't forget makewhatis(8), whatis(1), and apropos(1).

There's also this: http://hints.macworld.com/article.php?story=20030630060922242



[ Reply to This | # ]
Open formatted man pages in Preview from the command line
Authored by: captainulf on May 12, '11 11:57:25AM

I just want to give a shout out to Bwana from Bruji http://www.bruji.com/bwana/index.html I've been viewing man pages in Safari for years using this great free tool



[ Reply to This | # ]
Open formatted man pages in Preview from the command line
Authored by: bhas on May 12, '11 01:18:48PM

Nowadays I use iMan from here: http://iman-macosx.sourceforge.net/
Brilliant app with a commandline version.



[ Reply to This | # ]
Open formatted man pages in Preview from the command line
Authored by: neslob on May 12, '11 12:36:15PM
I have this in my .profile, so I can just use pman openssl.

pman () {
    man -t "${1}" | open -f -a /Applications/Preview.app
}


[ Reply to This | # ]
Open formatted man pages in Preview from the command line
Authored by: wallybear on May 12, '11 01:41:53PM
Bwana it's a lot better. You just tipe man:command in Safari and you get a well formatted man page for your command, with working hyperlinks to related commands.
Ah, and it's free.

(http://www.bruji.com/cocoa/)


[ Reply to This | # ]
Open formatted man pages in Preview from the command line
Authored by: bglnelissen on May 12, '11 11:40:11PM
My way... I have this script in my $PATH, just need to say manpdf function.

#!/bin/bash
# manpdf
# open man pages asif is a PDF file

man -t "$1" | open -f -a preview


[ Reply to This | # ]
Open formatted man pages in Preview from the command line
Authored by: marksch on May 13, '11 09:30:54AM

Man2Html works great for me
http://qery.us/q9

---
Mark

Economy-x-Talk
Have your own custom software created
http://economy-x-talk.com



[ Reply to This | # ]
Open formatted man pages in Preview from the command line
Authored by: tom larkin on May 15, '11 09:00:05PM
I submitted this when Rob was still running things, he declined to post it since there were similar hints. Here it is, my function called "woman" to export man pages to pdf

function woman {
  tmpfile="/tmp/man ${*}.pdf"
  if [ \! -f "${tmpfile}" ]
  then
      man -t "${*}" | pstopdf -i -o "${tmpfile}"
  fi
  open "${tmpfile}"
}


[ Reply to This | # ]
how to change the font with "man -t"
Authored by: mjd3566 on May 17, '11 08:13:13AM
I really like this hint, but I was wondering if there is a way to make the font fixed width?

I am using a combination of what neslob and bglnelissen suggested, and I tried piping it through textutil to change the font, but then nothing happened at all (Preview opened, but nothing else):

function pman () {
      man -t "$1" | textutil -stdin -stdout -font "Courier New" | open -f -a preview
}

Am I doing something wrong? Or should I just not bother?

[ Reply to This | # ]
how to change the font with "man -t"
Authored by: jecwobble on May 18, '11 01:42:05PM

The output from man is PostScript. Textutil will be transforming the text of that PostScript, not setting any PostScript font settings.



[ Reply to This | # ]
Open formatted man pages in Preview from the command line
Authored by: scootermachorn on May 25, '11 02:28:12PM

The following script will open a man page as a PDF in Preview or as a text file in BBEdit, TextWrangler, or TextEdit. Previously converted man pages are stored in "/Users/Shared/Documents/man/" for reference and to save conversion time.

Hope this helps!

<code>
#!/bin/bash
# bbman -- converts man pages to plain text or PDF and opens them in your favorite text editor

## Written by Scott Russell, Information Systems Project Manager, Edward Lowe Foundation
## Last modified: Wed May 25 17:13:15 EDT 2011

ARGS=1
ERR_NOARGS=66

if [ $# -lt $ARGS ] ; then
echo
echo "Usage: `basename $0` < man-page > [pdf]"
echo
exit $ERR_NOARGS
fi

MANTEXT="/Users/Shared/Documents/man"
[[ ! -d "${MANTEXT}" ]] && mkdir -p "${MANTEXT}"

## If we haven't done this before, convert the man page to PDF or text
if [[ `man ${1}` ]] ; then

if [[ "${2}" == "pdf" ]] ; then

if [[ ! -f "${MANTEXT}/${1}.pdf" ]] ; then
man -t "${1}" | pstopdf -o "${MANTEXT}/${1}.pdf" -i -p
fi

## Open in Preview
open -a Preview "${MANTEXT}/${1}.pdf"

else

if [[ ! -f "${MANTEXT}/${1}.txt" ]] ; then
man $1 | col -b > "${MANTEXT}/${1}.txt"
## If SetFile is installed, set the file's creator to R*ch (BBEdit)
[ -f /Developer/Tools/SetFile ] && /Developer/Tools/SetFile -c R*ch "${MANTEXT}/${1}.txt"
fi

## Open in BBEdit or TextWrangler or TextEdit
bbedit "${MANTEXT}/${1}.txt" 2>/dev/null || edit "${MANTEXT}/${1}.txt" 2>/dev/null || open -e "${MANTEXT}/${1}.txt"

fi

fi

exit 0

</code>



[ Reply to This | # ]
Open formatted man pages in Preview from the command line
Authored by: billy.kessler on May 28, '11 11:27:20PM

Also try ManOpen (http://www.clindberg.org/projects/ManOpen.html), which does the job nicely. It also has a built-in command line call: "openman [command]" that opens the formatted man page in a new window without breaking your flow of work.



[ Reply to This | # ]