1 ### vim:ft=zsh:foldmethod=marker
2 ## wikipedia backend for lookup
3 ## Copyright: 2009, Frank Terbeck <ft@bewatermyfriend.org>
5 LOOKUP_guard || return 1
6 [[ -n ${lookup_describe} ]] &&
7 printf '%s' 'search wikipedia' &&
11 local -a comp_args private_completions
12 local -A known_locations
14 lookup_context="$(LOOKUP_context)"
17 # yeah, there are more... a lot more.
42 LOOKUP_guard -fd LOOKUP_help_${backend} ||
43 function LOOKUP_help_${backend}() {
44 LOOKUP_guard || return 1
46 printf 'usage: %s [-l <arg>] <query>\n' ${backend}
47 printf ' -l <location> use a specific non-default wikipedia location\n'
48 printf '\n Query wikipedia.org about stuff you don'\''t know. :-)\n'
49 printf '\nKnown location codes:\n'
50 for l in ${(kon)known_locations}; do
51 printf '%6s - %s\n' $l ${known_locations[$l]}
53 printf '\n There are more than that, obviously. Inclusion of codes had to stop\n'
54 printf ' somewhere, so I settled for codes, that had 100.000+ articles at the time\n'
55 printf ' of writing. The default location is '\''en'\'', which can be modified via the\n'
56 printf ' '\''default-location'\'' style in this context:\n'
57 printf ' %s\n' ${lookup_context}
58 printf '\n The completion code only completes the known locations by default. If your\n'
59 printf ' code is missing you can add it via the '\''my-completions'\'' list style,\n'
60 printf ' looked up in this context: '\'':completion:*:lookup-%s:'\''\n' ${backend}
61 printf '\nExamples:\n'
62 printf ' %% zstyle '\'':lookup:*:%s:*'\'' default-location de\n' ${backend}
63 printf ' %% zstyle '\'':completion:*:lookup-%s:'\'' my-completions gr:Greek\n' ${backend}
64 printf ' %% lookup %s zsh\n' ${backend}
65 printf ' %% lookup %s -l de zsh\n' ${backend}
66 printf ' %% lookup %s -l no zsh\n\n' ${backend}
68 LOOKUP_help && return 0
70 if [[ -n ${lookup_complete} ]] ; then
72 zstyle -a ":completion:${curcontext}" my-completions private_completions
74 LOOKUP_guard -fd __lookup_${backend}_known_locations ||
75 function __lookup_${backend}_known_locations() {
79 ls=(${private_completions})
80 for l in ${(k)known_locations}; do
81 ls+=("$l:${known_locations[$l]}")
83 _describe -t leo_langs 'known locations' ls
87 '-l[choose a wikipedia flavour]:known locations:__lookup_'${backend}'_known_locations'
88 '*:wikipedia search:true'
91 _arguments -s -w -A '-*' ${comp_args} && return 0
92 _message 'wikipedia search'
100 zstyle -s "${lookup_context}" default-location loc || loc='en'
102 lu_parseopts_args=( l string )
103 LOOKUP_parseopts "$@" || return 1
104 [[ -n ${opts[-l]} ]] && loc="${opts[-l]}"
107 LOOKUP_query_handler || return 1
108 if [[ -z ${QUERY} ]] ; then
114 LOOKUP_browser "http://${loc}.wikipedia.org/w/wiki.phtml?search=${QUERY}&go=Go"