#!/bin/sh
# $Id: google,v 1.2 2001/12/23 10:15:18 proff Exp $
# elvis: google		-- Search the web using Google (www.google.com)
. surfraw || exit 1

w3_config_hook () {
def   SURFRAW_google_results $SURFRAW_results
def   SURFRAW_google_search search
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
  Surfraw search the web using Google (www.google.com)
Local options:
  -results=NUM                  Number of search results returned
                                Default: $SURFRAW_google_results
                                Environment: SURFRAW_google_results
  -search=                      Specialized search on topic
          bsd           |       BSD
          linux         |       Linux
          mac           |       Apple Macintosh
          unclesam              U.S. Government
                                Environment: SURFRAW_google_search
EOF
    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
	-results=*) setopt   SURFRAW_google_results $optarg	;;
	-search=*)  setopt   SURFRAW_google_search  $optarg	;;
	*) return 1 ;;
    esac
    return 0
}

w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments
if test -z "$w3_args"; then
    w3_browse_url "http://www.google.com/"
else
    escaped_args=`w3_url_of_arg $w3_args`
    w3_browse_url "http://www.google.com/${SURFRAW_google_search}?q=${escaped_args}&num=${SURFRAW_google_results}"
fi
