File: google

package info (click to toggle)
surfraw 2.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,624 kB
  • sloc: sh: 7,977; perl: 824; makefile: 277
file content (129 lines) | stat: -rwxr-xr-x 4,389 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
# $Id$
# 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
    defyn SURFRAW_google_lucky 0
    def   SURFRAW_google_country us
    def   SURFRAW_google_safe default
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
  Surfraw search the web using Google (www.google.com)
Local options:
  -l, -lucky                    Feeling lucky? Jump to first result.
  -results=NUM                  Number of search results returned
                                Default: $SURFRAW_google_results
                                Environment: SURFRAW_google_results
  -search=                      Specialized search on topic
	  images	|	Images
	  videos	|	Videos
	  maps		|	Maps
	  groups	|	groups
	  news		|	News
          bsd           |       BSD
          linux         |       Linux
          mac           |       Apple Macintosh
          unclesam      |       U.S. Government
                                Environment: SURFRAW_google_search
  -country=			Select regional google site
				Default is us (google.com)
	   <ISO 3166 alpha-2 code>
				Environment: SURFRAW_google_country
  -i, -images                   Image Search (same as -search=images)
  -v, -videos                   Video Search (same as -search=videos)
  -m, -maps                     Map Search (same as -search=maps)
  -n, -news                     News Search (same as -search=news)
  -G, -groups                   Groups Search (same as -search=groups)
  -safe=                        Safe Search level
        default         |       Default: $SURFRAW_google_safe
	off             |       Environment: SURFRAW_google_safe
	moderate        |
	strict          |
EOF
    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
    -r*=*)      setopt   SURFRAW_google_results "$optarg" ;;
    -sa*=*)     setopt   SURFRAW_google_safe    "$optarg" ;;
    -s*=*)      setopt   SURFRAW_google_search  "$optarg" ;;
    -l|-lu*)    setoptyn SURFRAW_google_lucky   1         ;;
    -c=*) 	setopt	 SURFRAW_google_country "$optarg" ;;
    -i*)        setopt   SURFRAW_google_search  images    ;;
    -v*)        setopt   SURFRAW_google_search  videos    ;;
    -m*)        setopt   SURFRAW_google_search  maps      ;;
    -n|-news)   setopt   SURFRAW_google_search  news      ;;
    -G|-gr|-groups) setopt   SURFRAW_google_search  groups    ;;
    *) return 1 ;;
    esac
    return 0
}

w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments

# Use SURFRAW_lang if present and the country has not been changed
if test -n "$SURFRAW_lang" -a "$SURFRAW_google_country" = "us"; then
    SURFRAW_google_country="$SURFRAW_lang";
fi

case "$SURFRAW_google_country" in
  af|ag|ai|ar|au|bd|bn|bo|br|bs|bw|by|bz|co|cu|do|ec|eg|et|fj|gi|gt|hk|jm|ly|mt|mx|my|na|nf|ng|ni|np|nz|om|pa|pe|ph|pk|pr|py|qa|sa|sb|sg|sv|tj|tr|tw|ua|ug|uy|vn) domain="com.${SURFRAW_google_country}" ;;
  cr|id|il|in|jp|ke|kh|kr|ls|ma|th|uk|uz|vc|ve|vg|vi|ck|yu|za|zm|zw) domain="co.${SURFRAW_google_country}" ;;
  us) domain="com";;
  *)  domain="$SURFRAW_google_country" ;;
esac

safe=""
case "$SURFRAW_google_safe" in
  strict)   safe="&safe=strict"   ;;
  moderate) safe="&safe=moderate" ;;
  off)      safe="&safe=off"      ;;
esac

url="https://"

if test -z "$w3_args" ; then
    case "$SURFRAW_google_search" in
	i*) url="${url}images" ;;
	m*) url="${url}maps"   ;;
	g*) url="${url}groups" ;;
	n*) url="${url}news"   ;;
	v*) url="${url}video"  ;;
	*)  url="${url}www"    ;;
    esac
    url="${url}.google.${domain}"
else
    search="$SURFRAW_google_search"
    case "$SURFRAW_google_search" in
	v*) url="${url}www"; search="search"; extra="&tbo=p&tbm=vid";;
	i*) url="${url}images" ; search="images";;
	m*) url="${url}maps"   ; search=maps    ;;
	g*) url="${url}groups" ; search=groups  ;;
	n*) url="${url}news"   ; search=news    ;;
	*)  url="${url}www"    ;;
    esac

    url="${url}.google.${domain}/${search}"
    escaped_args=`w3_url_of_arg $w3_args`
    url="${url}?q=${escaped_args}&num=${SURFRAW_google_results}"
    if [ "$SURFRAW_google_lucky" = 1 ]; then
	button=`w3_url_escape "I'm Feeling Lucky"`
	url="${url}&btnI=$button"
    fi
    url="${url}${safe}${extra}"
fi

w3_browse_url "$url"