Last active
December 20, 2015 18:18
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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