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

Bash Function to open man pages in new terminal window UNIX

When I'm stumbling around the command line, I usually need to keep various man pages open for reference. I always forget I can get a dedicated man window from the Help or Contextual menus. This bash function allows you to open a man page in a new window directly from the command line.

function man { if [ $# -eq 1 ] ; then open x-man-page://$1 ; elif [ $# -eq 2 ] ; then open x-man-page://$1/$2 ; fi }

Just put this function in your .bashrc file, and when you use the man command, the information opens in Terminal's Man Page specific window setting style. If you don't want to override the default 'man' command operation, you can change the function name to something else.

This function expands on OS X's x-man-page url scheme. And of course, there are plenty of alternate ways to view man pages such as in preview, ManOpen, or Bwana.

Smallduck is the true author of this hint; I'm merely spreading the word.
    •    
  • Currently 2.70 / 5
  You rated: 5 / 5 (10 votes cast)
 
[6,753 views]  

Bash Function to open man pages in new terminal window | 14 comments | Create New Account
Click here to return to the 'Bash Function to open man pages in new terminal window' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Bash Function to open man pages in new terminal window
Authored by: Brethil on Dec 30, '13 07:52:25AM

Please check hints before (and after) posting.

For this line to work one has to replace "$" with "$".



[ Reply to This | # ]
Bash Function to open man pages in new terminal window
Authored by: Strod on Dec 30, '13 08:24:05AM
'For this line to work one has to replace "$" with "$".'

Wait... what?

I could say something snarky like "Please check comments before (and after) posting", but I don't want to... ah, what the heck, I already wrote it. ;-b

[ Reply to This | # ]

Bash Function to open man pages in new terminal window
Authored by: benwiggy on Dec 30, '13 10:51:20AM

Just in case it's not obvious, I'm guessing he meant that the $ in the hint should be replaced by $, but presumably the &code got auto-converted by the forum in the comment, but not in the hint.



[ Reply to This | # ]
Bash Function to open man pages in new terminal window
Authored by: Brethil on Dec 30, '13 11:46:37AM

Sorry, exactly as the above poster said ;-)



[ Reply to This | # ]
Bash Function to open man pages in new terminal window
Authored by: macbates on Dec 30, '13 09:30:30AM

The command does seem to be incorrect. If you copy/paste it into a Terminal window, you get a continuation prompt:

$ function man { if [ $# -eq 1 ] ; then open x-man-page://$1 ; elif [ $# -eq 2 ] ; then open x-man-page://$1/$2 ; fi }
>

Not sure what replacing a $ with a $ does, bit something is not quite right.



[ Reply to This | # ]
Bash Function to open man pages in new terminal window
Authored by: joestalin on Dec 30, '13 09:55:25AM
I'm using the following:
function manp() { man -t "$1" | open -f -a Preview }
"man" itself is untouched, but if I type
manp foo
, it opens the man page for foo in Preview, prettified as a PDF. It can be slow for long man pages, but it's handy.

[ Reply to This | # ]
Bash Function to open man pages in new terminal window
Authored by: davidallie on Dec 31, '13 11:56:18AM

joestalin, what happens to the "prettified" man-page that Preview creates once you quit Preview? Is that "page" deleted or does it remain in a cache somewhere... and if so, where?

-- David Allie



[ Reply to This | # ]
Bash Function to open man pages in new terminal window
Authored by: transeau on Dec 31, '13 09:11:57AM

Why not just correct the hint?

function man { if [ $# -eq 1 ] ; then open x-man-page://$1 ; elif [ $# -eq 2 ] ; then open x-man-page://$1/$2 ; fi }



[ Reply to This | # ]
Bash Function to open man pages in new terminal window
Authored by: davidallie on Dec 31, '13 12:16:13PM
I added the following to my .bash_profile file:

# open man-pages in new tab
mant() {
if [ $# -eq 1 ]; then open x-man-page://$1 ; elif [ $# -eq 2 ] ; then open x-man-page://$1/$2 ; fi
}


and if I enter 'mant ditto' it opens the man-page for ditto in a new window. Works great.

[ Reply to This | # ]
Anyone know how to do this in tcsh?
Authored by: Dave1439 on Dec 31, '13 11:44:44AM

Anyone know how to do this in tcsh?

I'm no command line expert. I know a few things, but clearly not enough to get this working, since my efforts to adapt this for tcsh so far have failed.

I'd appreciate anyone else's successful effort! :)



[ Reply to This | # ]
Bash Function to open man pages in new terminal window
Authored by: amusingfool on Dec 31, '13 07:20:05PM

Seems a lot easier to just open a browser tab, and type 'man pg' in the search bar there to get the man page that you want.



[ Reply to This | # ]
Bash Function to open man pages in new terminal window
Authored by: agentx on Jan 02, '14 10:48:03AM

Even better IMHO

http://www.bruji.com/bwana/



[ Reply to This | # ]
Bash Function to open man pages in new terminal window
Authored by: cnotarianni on Jan 06, '14 11:21:19AM

For me the best is ManOpen, a MacOS X GUI application for viewing Unix manual pages. Man pages can be opened by title, like command-line 'man' command, or using 'openman' command line tool, which is similar to 'man' command except it will display the man pages in ManOpen.app instead of directly to the terminal.

http://www.clindberg.org/projects/ManOpen.html

Edited on Jan 06, '14 11:24:51AM by cnotarianni



[ Reply to This | # ]
Bash Function to open man pages in new terminal window
Authored by: Alphaman on Feb 05, '14 01:49:40PM
Go to System Preferences, Keyboard, Shortcuts and then search for the Text section under Services. Therein, you'll find "Open man Page in Terminal", which by default is set to Cmd-Shift-M, though disabled. Enable it. Go back to Terminal, type a command, select it, then press Cmd-Shift-M. Voilą. Same as the context menu, but via the keyboard. Well, mostly.
Edited on Feb 05, '14 01:56:55PM by Alphaman


[ Reply to This | # ]