I've been encountering people recently who, for one reason or another, are unable to find information for themselves when they have a question on FreeBSD.
I propose an rtfm(1) command, and I've got some Perl code that works. If people are interested, I will continue with it, and write a man page. The source is attached. Sample output: (-s = simple, don't search sections 3, 4, or 9, and 'e' means 'exact', or 'use whatis instead of apropos') --------- $ rtfm -s -e ASCII Manual pages found: ascii(7) hexdump(1) map3270(5) mset(1) neqn(1) od(1) pfbtops(1) Found FAQ entries: 1.18. Where can I get ASCII/PostScript versions of the FAQ? http://www.freebsd.org/FAQ/FAQ19.html#19 1.19. Where can I get ASCII/PostScript versions of the Handbook? http://www.freebsd.org/FAQ/FAQ20.html#20 1.20. The ASCII handbook isn't plain text! http://www.freebsd.org/FAQ/FAQ21.html#21 -- Chris Costello <ch...@calldei.com> "I'll rob that rich person and give it to some poor deserving slob. That will *prove* I'm Robin Hood." -- Daffy Duck, "Robin Hood Daffy", [1958, Chuck Jones]
#!/usr/bin/perl -w # Copyright (c) 1999 Chris Costello # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. use IO::Socket; my ($mancnt, $line, @manuals, $manual, $simple, $exactword, @faqs); my ($http_socket); $mancnt = 0; $simple = 0; $exactword = 0; # Somehow I need to be able to try and find a 'closest mirror'. $http_server = 'www.freebsd.org'; $faq_path = '/FAQ'; &usage if $#ARGV < 0; while ($_ = $ARGV[0], /^-/) { shift(@ARGV); if (/^-s/) { $simple++; } # see simple description in man page elsif (/^-e/) { $exactword++; } elsif (/^-h/) { &usage } } $ent = $ARGV[0]; $prog = "whatis" if $exactword; $prog = "apropos" unless defined($prog); # First check to see if we have a man page. open(APROPOS, "$prog $ent|") || die "error encountered running $prog: $!"; while (defined($line = <APROPOS>)) { chomp($line); $mancnt++; if ($line =~ /$ent: nothing appropriate/) { last; } # innovation. $line =~ s/^(.+?)\(([0-9nqt]+?)\).*/$2 $1/g; push(@manuals, $line); } close(APROPOS); if ($mancnt > 0) { print "Manual pages found:\n"; foreach $manual (@manuals) { my ($sect, $mman) = split(/ /, $manual); if ($simple > 0 && ($sect =~ /[349qt]+/)) { next; } print " $mman($sect)\n"; } } $http_socket = IO::Socket::INET->new($http_server . ':80'); print $http_socket "GET $faq_path/ HTTP/1.0\r\n\r\n"; while (defined($line = <$http_socket>)) { chomp($line); # superiority. if ($line =~ /^<DD>(.+?)<A HREF=\"(.+?)\">(.+?)<.*$/) { my ($faq_ent, $faq_page, $faq_question); $faq_ent = $1; $faq_page = $2; $faq_question = $3; if ($faq_question =~ /$ent/) { push(@faqs, sprintf("%s|%s|%s", $faq_ent, $faq_page, $faq_question)); } } } close($http_socket); print "\nFound FAQ entries:\n"; foreach (@faqs) { my ($faq_ent, $faq_page, $faq_question) = split(/\|/); print " $faq_ent $faq_question\n http://$http_server/FAQ/$faq_page\n"; } # usage: # prints usage info and exits. sub usage { print STDERR "usage: rtfm command\n"; exit 1; }