There's probably a better way to do this, but I developed a fairly simple set of tools a while ago to allow me to run google, askJeeves, dictionary, or thesaurus searches from the command line, using perl to parse the search words into a valid URL and then passing that off to lynx. E.g.:
% google cool uses for perl will start lynx in your terminal, at this address: http://www.google.com/search?q=cool+uses+for+perl
You'll need to have lynx in your path, you'll want to change the "use lib" statement in the four tools to the location that the browse.pm module is installed at, and you might need to change the netscape_path and mozilla_path vars at the bottom of browse.pm.
Enjoy!
browse.pm:
dictionary:#!/usr/bin/perl package browse; use warnings; use strict; use Exporter (); @ISA = qw(Exporter); @EXPORT_OK = qw( jeeves google dictionary thesaurus ); use Getopt::Long; our %pars; sub browser_cmdline { DoGetOptions () if scalar @ARGV; my $site = shift () or die "no site in browse::browser_cmd +line\n"; my $bDontUseArgv = shift () || 0; my $sSearch = join '+', @ARGV unless $bDontUseArgv; # Replace quotes with http friendly %22-s, and replace whitespace +with # query-friendly '+'-s # $sSearch =~ s/"/%22/g; $sSearch =~ s/\s+/+/g; $site .= $sSearch; my $str = ( $pars{browser} eq '' ) ? "lynx -cookies A $site + " : ( $pars{browser} =~ /^m/ ) ? mozilla_path () . " $site +&" : netscape_path () . " $site &"; print "$str\n" and return if $pars{norun}; system $str; } </readmore> sub jeeves { browser_cmdline 'http://www.ask.com/main/askjeeves.asp?ask='; } sub google { browser_cmdline 'http://www.google.com/search?q='; } sub dictionary { browser_cmdline 'http://dictionary.reference.com/search?q='; } sub thesaurus { browser_cmdline 'http://thesaurus.reference.com/search?q='; } sub DoGetOptions { %pars = ( browser => "", norun => 0, help => 0, usage => 0, ); GetOptions ( \%pars, 'browser=s', 'norun', 'help', 'usage', ) or die "bad options $!"; my $help_txt = qq{\tgoogle/jeeves/dictionary/thesaurus \t[-browser] [-norun] [-help] [-usage] \tsearch words list google and jeeves perform a search (at the expected location) on the given words. dictionary looks up the first word on dictionary.com. Quoted strings must be enclosed in single quotes: google '\"one two three\"' -browser n[etscape] launches the search in netscape7, -browser m[ozilla] launches the search in mozilla (default is +lynx). -norun prints out the search URL, but doesn't load it.\n}; die $help_txt if $pars{help} || $pars{usage}; } sub netscape_path { "/usr/local/bin/netscape" } sub mozilla_path { "/usr/local/bin/mozilla" } 1;
google:#!/usr/bin/perl use warnings; use strict; use lib '/home/kester/bin/'; use browse qw( dictionary ); dictionary ();
thesaurus:#!/usr/bin/perl use warnings; use strict; use lib '/home/kester/bin/'; use browse qw( google ); google ();
jeeves:#!/usr/bin/perl use warnings; use strict; use lib '/home/kester/bin/'; use browse qw( thesaurus ); thesaurus ();
#!/usr/bin/perl use warnings; use strict; use lib '/home/kester/bin/'; use browse qw( jeeves ); jeeves ();
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |