1 ### vim:ft=zsh:foldmethod=marker
2 ## usenet search backend for lookup via groups.google.com
3 ## Copyright: 2009, Frank Terbeck <ft@bewatermyfriend.org>
5 LOOKUP_guard || return 1
6 [[ -n ${lookup_describe} ]] &&
7 printf '%s' 'usenet search' &&
14 lookup_context="$(LOOKUP_context)"
17 text 'Free text search'
18 msgid 'Search for Message-ID: header'
19 author 'Search for a specific author'
22 LOOKUP_guard -fd LOOKUP_help_${backend} ||
23 function LOOKUP_help_${backend}() {
24 LOOKUP_guard || return 1
26 printf 'usage: %s [-{t,m}] [-a <arg>] <query>\n' ${backend}
27 printf ' -m search for message id\n'
28 printf ' -t free text search\n'
29 printf ' -a <author> search for messages by <author>\n'
30 printf '\n Search google'\''s usenet archives via groups.google.com.\n'
31 printf '\n Per default, free text searches are done, which can be modified via the\n'
32 printf ' '\''default-mode'\'' style in this context: %s\n\n' ${lookup_context}
33 for m in ${(k)known_modes} ; do
34 printf '%8s - %s\n' $m ${known_modes[$m]}
36 printf '\n As an exception the <query> argument may be empty in author mode.\n'
37 printf ' If you set default-mode to '\''author'\'', you may also set the\n'
38 printf ' '\''default-author'\'' style (which defaults to '\''Joe User'\'').\n'
39 printf '\nExamples:\n'
40 printf ' %% zstyle '\'':lookup:*:%s:*'\'' default-mode author\n' ${backend}
41 printf ' %% zstyle '\'':lookup:*:%s:*'\'' default-author "Dr. Foo Bar"\n' ${backend}
42 printf ' %% lookup %s zsh prompt colours\n' ${backend}
43 printf ' %% lookup %s -a pws Bugs in zsh\n\n' ${backend}
45 LOOKUP_help && return 0
47 if [[ -n ${lookup_complete} ]] ; then
49 '-a[specify author]:author:'
50 '-m[search for message id]:message id:'
51 '-t[free text search]:text:'
52 '*:usenet search string:true'
55 _arguments -s -w -A '-*' ${comp_args} && return 0
56 _message 'usenet search string'
64 lu_parseopts_args=( m bool t bool a string )
65 LOOKUP_parseopts "$@" || return 1
66 [[ ${opts[-t]} == 'yes' ]] && mode='text'
67 [[ ${opts[-m]} == 'yes' ]] && mode='msgid'
68 if [[ -n ${opts[-a]} ]] ; then
70 author="&as_uauthors=$(LOOKUP_encode ${opts[-a]})"
73 if [[ -z ${mode} ]] ; then
74 zstyle -s "${lookup_context}" default-mode mode || mode='text'
75 if [[ mode == 'author' ]] && [[ -z ${author} ]] ; then
77 zstyle -s "${lookup_context}" default-author a || a='Joe User'
78 author="&as_uauthors=$(LOOKUP_encode $a})"
83 LOOKUP_query_handler || return 1
84 if [[ -z ${(Mk)known_modes:#$mode} ]] ; then
85 printf 'Unknown mode: '\''%s'\''.\n\n' ${mode}
88 if [[ -z ${QUERY} ]] && [[ ${mode} != 'author' ]] ; then
94 if [[ ${mode} == 'msgid' ]] ; then
95 LOOKUP_browser "http://groups.google.com/groups?selm=${QUERY}"
99 LOOKUP_browser "http://groups.google.com/groups?q=${QUERY}${author}"