Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Last active December 20, 2015 18:18
Show Gist options
  • Save waffle2k/6174637 to your computer and use it in GitHub Desktop.
Save waffle2k/6174637 to your computer and use it in GitHub Desktop.
Sometimes I just type "man something-or-other" and would like google to take over if the man page does exist.
#!/usr/bin/perl
use strict;
$|++; # piping hot!
my $BROWSER = 'chromium-browser';
my $man = '/usr/bin/man';
sub googleit {
my $search = join( " ", @ARGV );
die 'no search term provided'
if $search =~ /^\s*$/;
$search =~ s/\s+/\+/g;
my $url = "www.google.com/?q=$search";
system( "$BROWSER $url" );
}
# Test if it's a man page
my @r =`$man -f $ARGV[0] 2>&1`;
if( grep { /nothing appropriate/ } @r ){
my $s = join( " ", split( /-/, $ARGV[0] ) );
googleit( $s );
exit 0;
}
system( "$man " . join( " ", @ARGV ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment