Command-line Google Search via find

Just for fun...

$ find -type m -name "glendale, ca coffee"
$ find -type m -name "glendale, ca smog check"
$ find -type g -name "cool bash commands"

The code:

# "Install" (I use that term loosely)
# - Paste the function below in your .bashrc / .profile / .zshrc / etc.
# Usage: find /usr/local -type [m|g] -name [KEYWORD]
# * -type m : google maps search
# * -type g : google search
# * all other types pass through to find
# Notes: 
# Tested on Ubuntu with ZSH. Comment's, suggestions, etc. welcome.
function find {
  if [ `uname -s` = "Darwin" ]; then
    $browser="open"
  fi
  test "$browser" || browser=`which chromium-browser`
  test "$browser" || browser=`which google-chrome`
  test "$browser" || browser=`which firefox`
  query="`echo "[email protected]" | sed -e 's:^[a-z\/\~\.]* ::' -e 's/-type [mg]//' -e 's/-name//'`"
  if [[ $@ =~ "-type m" ]]; then
    $browser "http://maps.google.com/?q=$query" 2>&1 > /dev/null &
  elif [[ $@ =~ "-type g" ]]; then
    $browser "http://www.google.com/search?q=$query" 2>&1 > /dev/null &
  else
    /usr/bin/find $@
  fi
}

get the gist

Published on