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

A revised fix for the apropros long-entry problem UNIX
I'm frustrated and surprised that the problems with apropos have still not been fixed. I noticed this was discussed here before, but apparently those fixes don't work on my current install of Mac OS X 10.4.9. Using ideas from the prior hint, I added the following as a fix in my .bash_profile:
function aproposFunc() {
  width=`stty size | cut -d  -f2`; apropos $* | cut -c1-$width;
}
alias apropos=aproposFunc
Background:

For those not aware, the problem causes many lines (or pages) of extra information to be printed when you execute apropos key. The prior fix involved limiting the line-length as a pipe after the $PAGER variable (i.e. less), or using the -S command-line option. The current implementation of apropos no longer uses the $PAGER variable, but instead becomes a grep on a large text file at /usr/share/man/whatis. That text file is built by a system process, but perhaps ends up with the over-extended lines because of problems between makewhatis and the man pages' formatting.

[robg adds: This one didn't work for me in testing -- apropos serial returned the same long text as it did before ... if anyone can fix the code, please post in the comments. Note that I had to add single quotes around the alias entry in my .profile file to get the alias recognized.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[5,024 views]  

A revised fix for the apropros long-entry problem | 5 comments | Create New Account
Click here to return to the 'A revised fix for the apropros long-entry problem' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A revised fix for the apropros long-entry problem
Authored by: hbp4c on Mar 23, '07 08:29:38AM
There is a set of quotation marks missing after the delimiter:
function aproposFunc() {
        width=`stty size | cut -d " " -f2`; apropos $* | cut -c1-$width;
}
alias apropos=aproposFunc


[ Reply to This | # ]
A revised fix for the apropros long-entry problem
Authored by: ThaneQ on Mar 23, '07 12:28:08PM

It looks like the html editor in the Mac OS X Hints web pages messed me up. There was a delimiter after the -d in my original text.

In the middle I have
cut -d\ -f2
In other words, a downslash and 2 spaces after the -d.

Sorry for the confusion.



[ Reply to This | # ]
A workaround
Authored by: lincd0 on Mar 23, '07 08:30:18AM

The graphical man page reader ManOpen returns correct results from an apropos query, without the garbage. It comes with a POSIX utility so you can access it from the command line. Won't work in a remote terminal session, obviously.



[ Reply to This | # ]
A revised fix for the apropros long-entry problem
Authored by: plambert on Mar 23, '07 05:35:22PM

If you use bash as your shell, put this in your .bash_profile:

apropos() { /usr/bin/apropos "$@" | less -iS; }

Paul



[ Reply to This | # ]
A revised fix for the apropros long-entry problem
Authored by: lihtox on Mar 23, '07 09:16:58PM
The previous fix mentioned changing apropos itself, so I played around with the new version of apropos and came up with the following apropos patch:

1. Right before the line while ["$1" != "" ], add the line width=`stty size |cut -d -f2`

2. After that line is a line that says if grep -"$grepopt1" "$grepopt2""$1" $d/whatis Add |cut -c1-$width to the end of that line.

Thanks for the inspiration!

[ Reply to This | # ]