9

Which .conf file do I need to edit in order to view man pages in a web browser? I'd like to use Google Chrome to do this.

Is this possible?

4 Answers 4

7

One way to do this is to put the following command in ~/.profile:

export PAGER="col -b  | open -a /Applications/Safari.app -f"

The PAGER environmental variable controls what program man uses to display man pages. the col command removes all of the backspace-formatting from the man page. The open command saves the output as a temporary text file and opens it with Safari.app.

Or you can edit the PAGER variable in /private/etc/man.conf. You could also probably edit the NROFF variable and eliminate the need to use col -b. See the man page for man.conf.

2
  • 2
    Thanks Nathan. That does the trick perfectly. I've just altered the line to read: export PAGER="col -b | open -a /Applications/Google\ Chrome.app -f" so it'll open in Chrome instead of Safari.
    – boehj
    Commented May 21, 2011 at 0:35
  • 2
    I'd been wanting to do this for myself anyway, and I'm glad I finally found time to look into it. I used TextWrangler with the command /usr/bin/edit --view-top --clean -t "Man page" Commented May 21, 2011 at 1:13
6

http://www.bruji.com/bwana/ is exactly what you're looking for.

1
  • Cheers. That does look interesting, esp. "We just threw in some color, some bold headers and cleaned it up a bit, so they go easy on the eye." I wonder if I can get such functionality from further editing a .conf file?
    – boehj
    Commented May 21, 2011 at 2:12
6

You can add a function to your ~/.bash_profile:

function gman () {
     man "$1" | col -b > "/tmp/$1"
     open -a "/Applications/Google Chrome.app" "/tmp/$1"
}
5
  • This function wasn't working for me Graham. Not sure why.
    – boehj
    Commented May 21, 2011 at 0:39
  • Is Google Chrome in /Applications/ or somewhere else?
    – Graham
    Commented May 21, 2011 at 3:51
  • It's in /Applications/.
    – boehj
    Commented May 21, 2011 at 8:06
  • Just an additional step. After adding the function in profile folder. Make sure to source it or reopen terminal. link source ~/.profile
    – Bharath
    Commented Nov 23, 2015 at 10:39
  • In Safari I had to add an extension like /tmp/$1.txt.
    – 1.61803
    Commented Feb 2, 2017 at 10:43
0

Similar to the solution by graham, but opening the HTML version in the browser:

function htman {
    groff -Thtml -mandoc -c $(man --path $1) > /tmp/$1.html
    open /tmp/$1.html
}

(Use >! instead of > for zsh to allow overwriting of the file.)

4
  • I have not seen zsh fail to overwrite pre-existing files when I forget to type >> instead of >
    – WGroleau
    Commented Mar 6, 2022 at 18:18
  • Can‘t you pipe this directly into open -f?
    – nohillside
    Commented Mar 6, 2022 at 18:34
  • No that makes the browser open the source as a text file, unfortunately.
    – js.
    Commented Mar 6, 2022 at 22:28
  • @WGroleau happened to me when I was writing that.
    – js.
    Commented Mar 6, 2022 at 22:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .