Add zsh-lookup sub-system
[grml-etc-core.git] / usr_share_grml / zsh / functions / Lookup / Backends / LOOKUP_be_deb_msgid
1 ### vim:ft=zsh:foldmethod=marker
2 ## lists.debian.org message-id search backend for lookup
3 ## Copyright: 2009, Frank Terbeck <ft@bewatermyfriend.org>
4
5 LOOKUP_guard || return 1
6 [[ -n ${lookup_describe} ]] &&
7     printf '%s' 'search lists.debian.org by message-ids' &&
8     return 0
9
10 local lookup_context
11 local -a comp_args
12
13 lookup_context="$(LOOKUP_context)"
14
15 LOOKUP_guard -fd LOOKUP_help_${backend} ||
16 function LOOKUP_help_${backend}() {
17     LOOKUP_guard || return 1
18     printf 'usage: %s [-1] <query>\n' ${backend}
19     printf '  -1    use the search'\''s first-hit option\n'
20     printf '\n Search Debian[1]'\''s Mailinglist Archive[2] my Message-ID: header.\n'
21     printf ' If you always want to use the -1 option, you may set the use-first-hit\n'
22     printf ' style in this context: %s\n' ${lookup_context}
23     printf '\nExamples:\n'
24     printf ' %% lookup %s 20090215095848.GA21661@schmehl.info\n' ${backend}
25     printf ' %% lookup %s -1 20090215095848.GA21661@schmehl.info\n' ${backend}
26     printf ' %% zstyle '\'':lookup:*:%s:*'\'' use-first-hit true\n' ${backend}
27     printf '\n[1] <http://www.debian.org>\n'
28     printf '[2] <http://lists.debian.org>\n'
29 }
30 LOOKUP_help && return 0
31
32 if [[ -n ${lookup_complete} ]] ; then
33     comp_args=(
34         '-1[use /firsthit option]'
35         '*:message-id for l.d.o:true'
36     )
37
38     _arguments -s -w -A '-*' ${comp_args} && return 0
39     _message 'message-id for l.d.o'
40     return 0
41 fi
42
43 local end
44 local -A opts
45 local -x QUERY
46
47 lu_parseopts_args=( 1 bool )
48 LOOKUP_parseopts "$@" || return 1
49 [[ ${opts[-1]} == 'yes' ]] && end='/firsthit' || end='/links'
50 zstyle -t "${lookup_context}" use-first-hit && end='/firsthit'
51
52 QUERY="${args[*]}"
53 LOOKUP_query_handler || return 1
54 if [[ -z ${QUERY} ]] ; then
55     LOOKUP_help -f
56     return 1
57 fi
58
59 LOOKUP_encode -q
60 LOOKUP_browser "http://lists.debian.org/msgid-search/${QUERY}${end}"
61 return $?