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.

One common workflow of mine is to open a manual page in a terminal, then another terminal in which to test things. The man page is formatted to the initial dimensions of the first terminal. When I now resize my windows (or have my WM do that for me automatically), there is either a gap to the right of the preformatted page, or lines wrap. At this point I usually q(uit) and !! (run again), which loses my position in the page.

I assume the formatting process is quite CPU intensive, or maybe it stems from ancient times of fixed terminal sizes. The less pager dynamically reacts to terminal resize events, so it should be possible in theory.

I tried perusing man pages, searching the Web, asking on IRC -- the whole lot -- but couldn't come up with anything.

  • Can I trigger reformatting from within or outside of the man utility?

  • Is there a version of the man utility that resizes the page dynamically?

  • Is there way to customize some part of the formatting/display process to make it update on SIGWINCH?

share|improve this question
    
man actually uses less as the pager; you can hit h in a man page to get the less help screen. I'm not sure why it doesn't dynamically resize man pages –  Michael Mrozek Apr 15 '11 at 14:44
2  
The problem appears to be that man renders the output to the width of the term. What you need is a pager that can bookmark where you are in the document, re-execute man (which it really has no idea about since it's piped to it) and return to the bookmark. Alternatively, a new man command that incorporates a pager. –  nix Apr 15 '11 at 14:48
add comment

2 Answers

up vote 8 down vote accepted

The basic problem is that the formatting is done by one program and the paging is done by another. Even if the formatter were to get a signal that the window size has changed and reformat the text for the new window size, all it can do is feed new text down the pipeline to the pager. There's no way for the pager to know with certainty what position in the new stream corresponds to the position in the old stream it was currently displaying.

What you need is for the pager to be able to do the reformatting. As @Robin Green said, that's HTML.

If you want to use HTML but still work in a terminal, you can tell man(1) to output in HTML and call a text-mode browser to display it.

man -Hlynx man

That will display the man(1) manpage in the lynx text-mode browser. Lynx does not directly respond to window size changes, but you can press ctrl-R and lynx will re-render the page for the new window size.

There are two other text-mode browsers that I know of: links and elinks. You could experiment with those and lynx and determine which give you the best experience for browsing man pages. You may want to use a custom configuration just for man pages and invoke a script that invokes the browser with that specific configuration.

You can put the man options you like into the MANOPT environment variable.

$ export MANOPT=-Hlynx
$ export MANOPT=-Hmanlynx # manlynx invokes lynx with a different configuration.

You will need to install the groff package for man to be able to generate HTML.

share|improve this answer
    
The limitation of the -H argument to man is that it doesn't use a webserver, but simply a small file. While this avoids any problems with misconfigured firewalls, it doesn't allow hyperlinks to other man pages to be generated (which at least some third-party man->html scripts support). –  Robin Green Apr 16 '11 at 6:12
1  
@Robin Green: The question is about supporting man pages in re-sizable terminal windows. In that context not using a webserver is not a limitation. And not having hyperlinks is not a limitation, since man pages displayed in less do not have hyperlinks. –  camh Apr 16 '11 at 6:31
    
That's true, it's certainly a valid answer. –  Robin Green Apr 16 '11 at 6:49
add comment

Convert the man pages to html on the fly using a suitable script such as manserver, viewing them in a web browser (which can of course be a text-based web browser like lynx).

This is presumably why no-one has solved this problem - because the problem became irrelevant with the development of man->html scripts.

share|improve this answer
add 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.