/usr/bin/perldig is in libperldoc-search-perl 0.01-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | #!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
use warnings;
use strict;
use Config;
use Perldoc::Search;
use Shell::POSIX::Select;
use File::Basename;
use Getopt::Std;
use Pod::Simple::TextContent;
our $LESS = "/usr/bin/less";
getopts("u", \my %opts);
my $searcher = Perldoc::Search->new();
if($opts{u}) {
print "This will take a couple of minutes, please stand by.\n";
$searcher->update();
print "Done\n";
} elsif(@ARGV) {
search();
}
###########################################
sub search {
###########################################
# Search documents containing both "swish" and "install"
my @hits = $searcher->search("@ARGV");
if ( !@hits ) {
print "No Results\n";
return;
}
my @select = ();
my %map = ();
# Shut up the goofy Shell::POSIX::Select implementation
our($Eof, $Reply);
for my $hit (@hits) {
if(! defined $hit) {
die "Before searching, please run the indexer: perldig -u\n";
}
my $path = my $org_path = $hit->path();
$path = $searcher->relative($path);
push @select, $path;
$map{$path} = $org_path;
}
@select = sort @select;
select my $file (@select) {
system "$LESS $map{$file}";
last;
}
}
__END__
=head1 NAME
perldig - Dig up keywords in the local Perl documentation
=head1 SYNOPSIS
# Update the index (required before first start)
perldig -u
# Search for a keyword
perldig keyword(s)
=head1 DESCRIPTION
When using C<perldig> for the first time, a new index needs to be
created. Just call
$ perldig -u
and everything happens automatically: A crawler will detect locally
installed Perl documentation pages, rummage through the POD and index
them. When this initial run has been completed, C<perldig> is ready to
process search requests:
$ perldig frobnicate
1) pod/perlguts.pod 2) pod/perlxstut.pod 3) pod/perlnewmod.pod
Enter number of choice:
The command above shows a search for the keyword C<frobnicate>. Yes,
that's a word used in the Perl documentation! It shows three hits and
asks the user to enter a number between 1 and 3 to open the selected
documentation page in a pager program (typically C<less>). In there,
an in-text search for the expression can be started by using the C</>
(slash) command.
If two or more keywords are given, the search will yield pages that
contain all of them. When searching for phrases, please include quotes
(make sure to quote the quotes so the shell doesn't eat them):
$ perldig '"floating point"'
The underlying I<swish-e> search engine also understands expressions
connected via AND and OR:
$ perldig "'floating point' AND approximate AND 'real number'"
To keep the index up to date, it is probably a good idea to run a
cronjob every morning:
00 4 * * * /usr/bin/perldig -u >/dev/null 2>&1
If you can read German, please check out this article in the "Linux-
Magazin", where this script was originally published:
http://www.linux-magazin.de/Artikel/ausgabe/2003/10/perl/perl.html
=head1 EXAMPLES
# Update/create the index
$ perldig -u
$ perldig frobnicate
1) pod/perlguts.pod 2) pod/perlxstut.pod 3) pod/perlnewmod.pod
Enter number of choice: 1
[ ... perlguts man page shows ... ]
=head1 FILES
C<perldig> puts the I<swish-e> index files into the folder C<.perldig>
in the user's home directory.
=head1 LEGALESE
Copyright 2003-2005 by Mike Schilli, all rights reserved.
This program is free software, you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 AUTHOR
2003, Mike Schilli <m@perlmeister.com>
|