To paraphrase myself on freebsd-questions: "What an interesting night of experimentation." Most of this post has already been tubified on the mailing list, but I want to get down some details, and make sure I can easily find the information later.

A small irritation about FreeBSD is man does not automatically adjust its line-length to account for the number of columns currently displayed in a particular xterm. So, after weeks of intermittent frustration and small, aborted attempts to determine why I couldn't get the man to do what I wanted, I decided a concerted effort was worth my time (that, and I asked for help ;)).

My goal was to have man whatever automatically adjust line-lenths based on the number of columns on the display device. Unexpectedly, after the initial flurry of emails with information leading toward a solution, the fix was the work of a single night.

The first solution was the following shell script.

dave@heffalump:~$ cat bin/man.sh
#!/bin/sh
mpage=`man -w $1`
tcols=`stty -a | grep columns | awk '{ print $6 }'`

zcat -f `man -w $1` | groff -Tutf8 -man -rIN=7n -rLL=`echo ${tcols} - 3 | bc`n - | less

The shell script above does the minimum - it adjusts the line-length of a given man page based on the number of columns being displayed. However, there were multiple problems.

  • man -k was unusable
  • my fingers kept typing man -k

Ok... maybe only one problem. Regardless, the lack of man -k was an irritant I'd not suffer gladly.

Knowing man adjusted line-length based on columns on FreeBSD-CURRENT caused me to look at the difference between man in HEAD and 8.1-RELEASE, where I discovered the man from HEAD is a shell script! Woohoo! That inspired a second solution: Take the shell script from HEAD, and install it for my user's use. That wasn't a complete solution, as apparently man's behavior in HEAD (regarding line-length) was the result of an outside factor. However, man being a shell script meant I could modify, so I did the following.

  • Check out the man from HEAD.

    $ svn checkout svn://svn.freebsd.org/base/head/usr.bin/man
    
  • Modify man.sh in the subversion checkout with the following patch.

    --- man.sh.orig 2011-01-19 22:41:34.000000000 -0600
    +++ man.sh      2011-01-19 22:41:33.000000000 -0600
    @@ -891,9 +891,10 @@
            search_whatis whatis "$@"
     }
    
    
    +cols=`stty -a | grep columns | awk '{ print $6 }'`
     EQN=/usr/bin/eqn
     COL=/usr/bin/col
    -NROFF='/usr/bin/groff -S -Wall -mtty-char -man'
    +NROFF='/usr/bin/groff -S -Wall -mtty-char -man -rLL=`echo $cols - 3 | bc`n'
     PIC=/usr/bin/pic
     SYSCTL=/sbin/sysctl
     TBL=/usr/bin/tbl
    #v-
    
  • Install fakeroot (needed to install the man pages).

  • Install the man from HEAD.

    $ fakeroot make install BINDIR=/home/dave/usr/bin MANDIR=/home/dave/usr/share/man/man NO_MANCOMPRESS="YES"
    
    • Note: The Makefile doesn't honor PREFIX, but does honor BINDIR/MANDIR.

Finally, my man pages are displayed in full-col-o-vision!

So, more gymnastics than I would like, but functional. I'll use this method until the new shell script version in HEAD makes it into the base of a release I'm running.

Thanks to all on the mailing list for the information and inspiration!