Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

right now when I run man smth or similar less is used to view it. However, on Mac OS X, I really like scrolling with touchpad instead on up/down or page-up/page-down buttons. Is there a way to just print text into the terminal instead of using less or more?

share|improve this question
    
@peth The default one. –  Halst Jun 27 '11 at 22:47
    
You can do it, but it'll make navigation and searching a pain. How about viewing the man pages in a GUI viewer? I don't know what's available in Carbon; in X there's xman, tkman, or whatever you have available. (Or there's Emacs, of course.) –  Gilles Jun 27 '11 at 22:56
    
less does scroll with the mouse scroll button for me. That maps to the touchpad of OSX I guess. So, maybe the terminal app has some kind of settings to allow this. –  phunehehe Jun 28 '11 at 3:12
add comment

2 Answers

up vote 5 down vote accepted

Not sure about OSX, but hopefully it's Unix-y enough...

In your $HOME/.bashrc add the following line:

export MANPAGER=cat

If you want all of your paging programs to act in this way, set PAGER instead. man will use MANPAGER if set, otherwise it falls back to PAGER, which if not set falls back to more.

share|improve this answer
    
Thanks, that works. However, do you know if there is a way to make scrolling start from the beginning of the document, not from the end? I guess this will bi tricky... –  Halst Jun 27 '11 at 21:43
    
You mean you would like the text with the order reversed? Last line first, and first line last? If so, use tac ... and yes, that stands for cat backwards. Or do you mean that you want the scrollbar left so that the top of the document is showing? If the latter, I have no idea. That would be terminal (and thus MacOSX "Terminal" specific). –  Mark Mann Jun 27 '11 at 21:53
    
Second one. Yeah, that's a pity... –  Halst Jun 27 '11 at 21:59
add comment

To get the effect you want, where you get a man page in a separate window with the view starting at the first page, add the following to your ~/.bash_profile:

function man {
    mf=`mktemp /tmp/$1-formatted-XXXXXXXXX`
    /usr/bin/man -t "$@" | pstopdf -i -o $mf
    mv $mf $mf.pdf
    open -W $mf.pdf
    rm $mf.pdf
}

You can log out and back in to activate it, or just reload the file with:

. ~/.bash_profile

The latter risks redefining things like the PATH variable with duplicate info.

This function overrides the man command, causing it to build a PDF-formatted version of the man page in a temporary file, open that in your PDF viewer (Preview, by default) and then remove the temporary PDF when you close the viewer. The idea being, your default PDF viewing program probably responds to the touchpad the way you want.

In order to get that last feature, where it removes the temporary PDF, I had to make open(1) wait until the PDF viewer closed before it proceeds. This means you can't continue to use your terminal window while the PDF stays open. One hack around this would be to remove the -W flag and follow the open command with something like sleep 1, which should be enough time for Preview to open. Another hack might be to replace the last line with something like this:

( sleep 60 ; rm $mf.pdf ) &

That schedules the rm command for 60 seconds in the future, certainly enough time.

share|improve this answer
    
Thanks, that's useful! Is there a way to adopt this beyond man command? i.e. set these actions as the default pager? (BTW, why remove the PDF if it is in /tmp folder anyway?). –  Halst Jun 27 '11 at 22:59
    
Re: "that's useful". Thanks. So upvote me. :) –  Warren Young Jun 27 '11 at 23:06
    
Re: broadening it: you could install a text editor that adds a command line shortcut which also understands the - convention for getting input from stdin, like MacVim, then set the PAGER environment variable to something like mvim -. (TextWrangler also installs a command-line shortcut, but I don't know if it understands -.) The main problem with this is that some things expecting a "pager" also expect that they can do things like terminal escape sequences, for formatting. That's why I had to resort to PDF formatting for the "man" case. –  Warren Young Jun 27 '11 at 23:10
    
Re: why remove the PDF? Just saving space and cleaning up after myself. Habit more than anything, really. If you don't mind all those temporary PDFs clogging up /tmp until something comes along to clean them up, go ahead and remove the -W and the rm command. –  Warren Young Jun 27 '11 at 23:11
1  
@Warren Young - Heresy! Sacrilege! If it cannot be easily viewed on 80x24 green phosphor, surely it isn't Unix. All kidding aside, this is a great solution. Upvote from me. –  Mark Mann Jun 27 '11 at 23:13
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.