Skip to content

Instantly share code, notes, and snippets.

@arisawa
Created March 3, 2013 11:17
Show Gist options
  • Save arisawa/5075681 to your computer and use it in GitHub Desktop.
Save arisawa/5075681 to your computer and use it in GitHub Desktop.
Execute google search in your browser
#!/usr/bin/env perl
=head1 DESCRIPTION
Execute google search in your browser
=head1 SYNOPSIS
% gg.pl [Options] Word(s)
Options:
--browser|-b Command to run your browser (required)
--num|-n Search nums (default:100)
--time|-t Search range (default:2y)
--lang|-l Search language (default:ja)
--help|-h brief help message
--man full documentaion
=cut
use strict;
use warnings;
use Getopt::Long qw/:config posix_default no_ignore_case bundling auto_help/;
use Pod::Usage qw/pod2usage/;
use URI::Escape ();
GetOptions(
\my %opts,
qw(browser|b=s num|n=s time|t=s lang|l=s help|h man)
) or pod2usage(1);
pod2usage(1) if ($opts{help});
pod2usage(-verbose => 2) if ($opts{man});
if (not @ARGV) {
die 'Search word is not found.';
}
my @words = @ARGV;
if (not defined $opts{browser}) {
die 'browser is not specified. e.g. "open -g -a Firefox"';
}
$opts{num} ||= 100;
$opts{time} ||= '2y';
$opts{lang} ||= 'ja';
my $url = sprintf(
"http://www.google.co.jp/search?q=%s&num=%s&as_qdr=%s&hl=%s&lr=lang_%s",
URI::Escape::uri_escape(join " ", @words),
$opts{num}, $opts{time}, $opts{lang}, $opts{lang},
);
my @command = split /\s+/, $opts{browser};
push @command, $url;
exec @command;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment