How can I make the man command not use a pager?

4

2

How can I force the man command to not use a pager, and instead output the whole manpage at once and keep all highlighting?

If I use man -P cat or man | cat, I lose highlighting.

tig

Posted 2009-12-24T21:19:36.380

Reputation: 3 906

2You need a better title. – SLaks – 2009-12-24T21:20:38.607

1@Slaks: You mean the answer isn't "Buy him a blackberry"? – mbarnett – 2009-12-24T21:22:40.537

@Matt: Exactly. – SLaks – 2009-12-24T21:24:31.017

Ops! Did not read it in this way :))) – None – 2009-12-24T21:29:16.530

Answers

7

Long reading of manuals for man, less, groff and grotty finally gave me answer

Highlighting by default is made using backspace sequences: c\bc => bold c, _\bc => underlined c. But if output as is using cat as pager just outputs plain c in both cases. Also blank lines are squeezed, so to do all this, pager must be set to ul | cat -s.

Pager can be set in many ways:

  1. using MANPAGER or PAGER variables (MANPAGER is better as PAGER affects not only man command)

    export MANPAGER='ul | cat -s'
    
  2. in man.conf

    PAGER       ul | cat -s
    
  3. using -P parameter

    cat -P 'ul | cat -s' …
    

    or

    alias man='man -P "ul | cat -s"'
    

tig

Posted 2009-12-24T21:19:36.380

Reputation: 3 906

+1, but I only need to use 'ul' as my pager to dump the output to the console with highlighting. I.e. man -P ul <command>. Ubuntu 12.04.2. – G-Wiz – 2013-07-17T03:52:33.377

2

man man

...
    PAGER          A program to use for interactively delivering
                        man's  output  to  the  screen.   If not set,
                        `more -s' is used.  See more(1).

Which means the pager is regulated by PAGER env. variable, Thus just define PAGER as

setenv PAGER cat

and enjoy.

Moisei

Posted 2009-12-24T21:19:36.380

Reputation: 131

Why the downvote? This may not be the optimal solution, but it's not incorrect. Try it: $ PAGER=cat man foobar. – bcat – 2009-12-24T21:44:25.283

Isn't using cat as a pager essentially the same thing as not using a pager at all? – bcat – 2009-12-24T21:46:20.170

The question is about not using a pager and this without loosing highlighting. – Pascal Thivent – 2009-12-24T21:47:29.880

When I try this approach, I lose highlighting (on Mac OS X and Ubuntu). – Brian Campbell – 2009-12-24T23:55:36.693

i also lose highlighting. as a comment in another answer points out, man -P ul or PAGER=ul man works. TIL about ul… – flying sheep – 2014-02-19T09:28:01.520

1

Alternatively, there's always the -P switch:

man -P cat foo

amphetamachine

Posted 2009-12-24T21:19:36.380

Reputation: 1 443

I already sad that with -P cat I use highlighting – tig – 2009-12-24T23:43:27.920

I checked my theory with <code>man -P cat man |tee foo.txt ; less -R foo.txt</code>. The formatting is still there; it just doesn't show up in the command window. – amphetamachine – 2010-01-04T22:55:25.333

1

This is not exactly what you want (you won't get the output in the console) but you could generate a dvi file with the content of a manual as explained in man's man:

man -l -Tdvi ./foo.1x.gz > ./foo.1x.dvi

This command will decompress and format the nroff source manual page ./foo.1x.gz into a device independent (dvi) file. The redi‐ rection is necessary as the -T flag causes output to be directed to stdout with no pager. The output could be viewed with a program such as xdvi or further processed into PostScript using a program such as dvips.

I've just tested this and opened the dvi file with evince: the highlighting is not lost.

Pascal Thivent

Posted 2009-12-24T21:19:36.380

Reputation: 1 492

man on mac has no -l and -T params – tig – 2009-12-24T23:46:34.573