1 ### vim:ft=zsh:foldmethod=marker
2 ## google search backend for lookup
3 ## Copyright: 2009, Frank Terbeck <ft@bewatermyfriend.org>
5 LOOKUP_guard || return 1
6 [[ -n ${lookup_describe} ]] && printf '%s' 'google websearch' && return 0
8 if [[ -n ${lookup_complete} ]] ; then
11 '-1[I'\''m Feeling Lucky!]'
12 '*:dict.leo.org query:true'
15 _arguments -s -w -A '-*' ${comp_args} && return 0
16 _message 'google query'
20 local mode lookup_context
23 lookup_context="$(LOOKUP_context)"
25 LOOKUP_guard -fd LOOKUP_help_${backend} ||
26 function LOOKUP_help_${backend}() {
27 LOOKUP_guard || return 1
28 printf 'usage: %s [-1] <query>\n' ${backend}
29 printf ' -1 Go directly to the first hit using "I'\''m Feeling Lucky"\n'
30 printf '\n Make web searches via google.com\n'
31 printf ' If you always want to use the -1 option, you may set the use-first-hit\n'
32 printf ' style in this context: %s\n' ${lookup_context}
33 printf '\nExamples:\n'
34 printf ' %% lookup %s zsh\n' ${backend}
35 printf ' %% lookup %s -1 openbsd\n' ${backend}
36 printf ' %% zstyle '\'':lookup:*:%s:*'\'' use-first-hit true\n\n' ${backend}
38 LOOKUP_help && return 0
40 lu_parseopts_args=( 1 bool )
41 LOOKUP_parseopts "$@" || return 1
43 if [[ ${opts[-1]} == 'yes' ]] ||
44 zstyle -t "${lookup_context}" use-first-hit ; then
46 mode='I'\''m Feeling Lucky'
47 mode="$(LOOKUP_encode ${mode})"
54 LOOKUP_query_handler || return 1
55 if [[ -z ${QUERY} ]] ; then
61 LOOKUP_browser "http://www.google.com/search?q=${QUERY}${mode}"