At: ashok.org.uk/2007/command-line-google

Command-line Google script

The Mac has a lovely command, open, which you can point at a file or URL and it will do the Right Thing.

Here's a little script that lets you Google from the command line. You can also use it with Gnome by calling gnome-open instead of open at the end of the script.


Copy this in to a file, somewhere on your path, and chmod a+x it (but then if you are going to use this, you most likely know that):

 #!/usr/bin/php
 <?php
 $url = 'http://www.google.com/';
 $qstring = urlencode(implode(' ',array_slice($argv,1)));
 if (($qstring)!='') {
   $url .= 'search?q='.$qstring;
 }
 exec("open '".escapeshellarg($url)."'");
 ?>

Now, when you google foo you will get a new browser or tab with your search in. Call it with no arguments to go to Google's home page.

I use this when I'm using a random wireless connection, and would rather not go to my personal start page, or just when I don't have a browser handy, and want to make a quick search.

Tagged: Code

Posted at 11:24 GMT, 11th December 2007.

No comments. Add one.