Bug#826280: notmuch: shortcut to list tags
[notmuch-archives.git] / f9 / 480e5e48d3b9fdff5eee272ee41d1e12d7edab
1 Return-Path: <jani@nikula.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 2974D431FBC\r
6         for <notmuch@notmuchmail.org>; Sat,  2 Mar 2013 05:59:25 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id 3UMsi8Q2ZuoA for <notmuch@notmuchmail.org>;\r
16         Sat,  2 Mar 2013 05:59:22 -0800 (PST)\r
17 Received: from mail-la0-f41.google.com (mail-la0-f41.google.com\r
18         [209.85.215.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 75071431FAE\r
21         for <notmuch@notmuchmail.org>; Sat,  2 Mar 2013 05:59:22 -0800 (PST)\r
22 Received: by mail-la0-f41.google.com with SMTP id fo12so3799725lab.28\r
23         for <notmuch@notmuchmail.org>; Sat, 02 Mar 2013 05:59:18 -0800 (PST)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=google.com; s=20120113;\r
26         h=x-received:from:to:cc:subject:date:message-id:x-mailer:mime-version\r
27         :content-type:content-transfer-encoding:x-gm-message-state;\r
28         bh=Io9UjuxI4w24YxTVti0DaJuMklkXppF3jick0RiU86M=;\r
29         b=aOsbfGZmFG2nST7QMpNjyXmJUahughCkBhU1iAPF55wAVJOsR+VjwtdAma/lNy4r9+\r
30         GCYTLGdLxpZDNUD+fx4fzW358WekZcXt6068qXiUzxrJkMo3/4umhH0OexMeKmy5iY2O\r
31         LTxv9udVe0bCwuMDkP7tDlyetp2851fjo9uvo7fgyN/oAwMlW5wkrNrNu9NEIRFpLGWk\r
32         eYpKdkUozP7D4exRVl78r7ixA5fKxY5nzMz7NZGf+NLi0NrQXA+24mO25W73DCr17PZy\r
33         zBOrxuOAAnQe28YdX20AjiilkvrUvZigQx0WaVnbE0EMWhmzV8bBP29LYaRdl4la2d4V\r
34         zODw==\r
35 X-Received: by 10.152.123.34 with SMTP id lx2mr12213837lab.52.1362232757962;\r
36         Sat, 02 Mar 2013 05:59:17 -0800 (PST)\r
37 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
38         [80.223.81.27])\r
39         by mx.google.com with ESMTPS id k15sm5219143lbd.6.2013.03.02.05.59.15\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Sat, 02 Mar 2013 05:59:16 -0800 (PST)\r
42 From: Jani Nikula <jani@nikula.org>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH] completion: complete bash completion rewrite\r
45 Date: Sat,  2 Mar 2013 15:59:11 +0200\r
46 Message-Id: <1362232751-9571-1-git-send-email-jani@nikula.org>\r
47 X-Mailer: git-send-email 1.7.10.4\r
48 MIME-Version: 1.0\r
49 Content-Type: text/plain; charset=UTF-8\r
50 Content-Transfer-Encoding: 8bit\r
51 X-Gm-Message-State:\r
52  ALoCoQnBWr2w6VgVpLhCorX1JRF5sLdjs1xTGVSB9TlCVLYY+aGhamiqXIZn8MzjhsCp0PjZCCN4\r
53 X-BeenThere: notmuch@notmuchmail.org\r
54 X-Mailman-Version: 2.1.13\r
55 Precedence: list\r
56 List-Id: "Use and development of the notmuch mail system."\r
57         <notmuch.notmuchmail.org>\r
58 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
59         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
60 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
61 List-Post: <mailto:notmuch@notmuchmail.org>\r
62 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
63 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
64         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
65 X-List-Received-Date: Sat, 02 Mar 2013 13:59:25 -0000\r
66 \r
67 Rewrite the bash completion script to actually do something\r
68 useful. There are still a few rough edges (documented as BUGS/TODO),\r
69 but it's already fairly good.\r
70 \r
71 In addition to completing all the notmuch keyword arguments, it does\r
72 some nice stuff, like complete tags on 'notmuch tag (+|-)<TAB>' and\r
73 config options on 'notmuch config (get|set) <TAB>'.\r
74 \r
75 This is all based on the bash-completion package [1], and will not\r
76 work without it.\r
77 \r
78 [1] http://bash-completion.alioth.debian.org/\r
79 \r
80 ---\r
81 \r
82 CAVEATS:\r
83 \r
84 This is pretty much "good enough" for me. The existing one was, IMHO,\r
85 practically useless.\r
86 \r
87 There may be dependencies on the version of the bash-completion\r
88 package. I do not know, and I don't have a huge interest in finding\r
89 out. That way lay dragons.\r
90 \r
91 Regardless, I think this is a *huge* improvement on the status quo for\r
92 anyone this works for. And if it doesn't, the loss is roughly\r
93 equivalent to the usefulness of the old completion script, i.e. "not\r
94 much". It's also a *much* more interesting starting point for anyone\r
95 wishing to improve upon.\r
96 ---\r
97  completion/notmuch-completion.bash |  333 ++++++++++++++++++++++++++++--------\r
98  1 file changed, 262 insertions(+), 71 deletions(-)\r
99  rewrite completion/notmuch-completion.bash (66%)\r
100 \r
101 diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash\r
102 dissimilarity index 66%\r
103 index 8665268..cbd10aa 100644\r
104 --- a/completion/notmuch-completion.bash\r
105 +++ b/completion/notmuch-completion.bash\r
106 @@ -1,71 +1,262 @@\r
107 -# Bash completion for notmuch\r
108 -#\r
109 -# Copyright © 2009 Carl Worth\r
110 -#\r
111 -# This program is free software: you can redistribute it and/or modify\r
112 -# it under the terms of the GNU General Public License as published by\r
113 -# the Free Software Foundation, either version 3 of the License, or\r
114 -# (at your option) any later version.\r
115 -#\r
116 -# This program is distributed in the hope that it will be useful,\r
117 -# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
118 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
119 -# GNU General Public License for more details.\r
120 -#\r
121 -# You should have received a copy of the GNU General Public License\r
122 -# along with this program.  If not, see http://www.gnu.org/licenses/ .\r
123 -#\r
124 -# Author: Carl Worth <cworth@cworth.org>\r
125 -#\r
126 -# Based on "notmuch help" as follows:\r
127 -#\r
128 -# Usage: notmuch <command> [args...]\r
129 -#\r
130 -# Where <command> and [args...] are as follows:\r
131 -#\r
132 -#      setup\r
133 -#\r
134 -#      new\r
135 -#\r
136 -#      search [options] <search-term> [...]\r
137 -#\r
138 -#      show <search-terms>\r
139 -#\r
140 -#      reply <search-terms>\r
141 -#\r
142 -#      tag +<tag>|-<tag> [...] [--] <search-terms> [...]\r
143 -#\r
144 -#      dump [<filename>]\r
145 -#\r
146 -#      restore <filename>\r
147 -#\r
148 -#      help [<command>]\r
149 -\r
150 -_notmuch()\r
151 -{\r
152 -    local current previous commands help_options\r
153 -\r
154 -    previous=${COMP_WORDS[COMP_CWORD-1]}\r
155 -    current="${COMP_WORDS[COMP_CWORD]}"\r
156 -\r
157 -    commands="setup new search show reply tag dump restore help"\r
158 -    help_options="setup new search show reply tag dump restore search-terms"\r
159 -    search_options="--max-threads= --first= --sort="\r
160 -\r
161 -    COMPREPLY=()\r
162 -\r
163 -    case $COMP_CWORD in\r
164 -        1)\r
165 -            COMPREPLY=( $(compgen -W "${commands}" -- ${current}) ) ;;\r
166 -        2)\r
167 -            case $previous in\r
168 -                help)\r
169 -                    COMPREPLY=( $(compgen -W "${help_options}" -- ${current}) ) ;;\r
170 -                search)\r
171 -                    COMPREPLY=( $(compgen -W "${search_options}" -- ${current}) ) ;;\r
172 -            esac\r
173 -            ;;\r
174 -    esac\r
175 -}\r
176 -\r
177 -complete -o default -o bashdefault -F _notmuch notmuch\r
178 +# bash completion for notmuch                              -*- shell-script -*-\r
179 +#\r
180 +# Copyright © 2013 Jani Nikula\r
181 +#\r
182 +# Based on the bash-completion package:\r
183 +# http://bash-completion.alioth.debian.org/\r
184 +#\r
185 +# This program is free software: you can redistribute it and/or modify\r
186 +# it under the terms of the GNU General Public License as published by\r
187 +# the Free Software Foundation, either version 2 of the License, or\r
188 +# (at your option) any later version.\r
189 +#\r
190 +# This program is distributed in the hope that it will be useful,\r
191 +# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
192 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
193 +# GNU General Public License for more details.\r
194 +#\r
195 +# You should have received a copy of the GNU General Public License\r
196 +# along with this program.  If not, see http://www.gnu.org/licenses/ .\r
197 +#\r
198 +# Author: Jani Nikula <jani@nikula.org>\r
199 +#\r
200 +#\r
201 +# BUGS/TODO:\r
202 +#\r
203 +# Add space after an --option without parameter (e.g. reply --decrypt)\r
204 +# on completion.\r
205 +#\r
206 +# Do not complete other options immediately after an --option= which\r
207 +# has no keyword value (e.g. reply --format-version=N).\r
208 +#\r
209 +# Filename completions for all file parameters (e.g. dump\r
210 +# --output=FILE or even config set database.path).\r
211 +#\r
212 +# Do not define _notmuch_commands at the top level.\r
213 +#\r
214 +# Consider completing options only if the string being completed\r
215 +# begins with '-' (i.e. do not offer option completions on\r
216 +# e.g. notmuch search <TAB>).\r
217 +#\r
218 +\r
219 +_notmuch_commands="config count dump help new reply restore search setup show tag"\r
220 +\r
221 +_notmuch_config()\r
222 +{\r
223 +    local cur prev words cword split\r
224 +    _init_completion || return\r
225 +\r
226 +    case "${prev}" in\r
227 +       config)\r
228 +           COMPREPLY=( $(compgen -W "get set list" -- ${cur}) )\r
229 +           return\r
230 +           ;;\r
231 +       get|set)\r
232 +           COMPREPLY=( $(compgen -W "`notmuch config list | sed 's/=.*\$//'`" -- ${cur}) )\r
233 +           return\r
234 +           ;;\r
235 +    esac\r
236 +}\r
237 +\r
238 +_notmuch_count()\r
239 +{\r
240 +    local cur prev words cword split\r
241 +    _init_completion -s || return\r
242 +\r
243 +    $split &&\r
244 +    case "${prev}" in\r
245 +       --output)\r
246 +           COMPREPLY=( $( compgen -W "messages threads" -- "${cur}" ) )\r
247 +           return\r
248 +           ;;\r
249 +       --exclude)\r
250 +           COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )\r
251 +           return\r
252 +           ;;\r
253 +    esac\r
254 +\r
255 +    local options="--output= --exclude="\r
256 +    compopt -o nospace\r
257 +    COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
258 +}\r
259 +\r
260 +_notmuch_dump()\r
261 +{\r
262 +    local cur prev words cword split\r
263 +    _init_completion -s || return\r
264 +\r
265 +    $split &&\r
266 +    case "${prev}" in\r
267 +       --format)\r
268 +           COMPREPLY=( $( compgen -W "sup batch-tag" -- "${cur}" ) )\r
269 +           return\r
270 +           ;;\r
271 +    esac\r
272 +\r
273 +    local options="--format= --output="\r
274 +    compopt -o nospace\r
275 +    COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
276 +}\r
277 +\r
278 +_notmuch_help()\r
279 +{\r
280 +    local cur prev words cword split\r
281 +    _init_completion || return\r
282 +\r
283 +    local help_topics="$_notmuch_commands hooks search-terms"\r
284 +    COMPREPLY=( $(compgen -W "${help_topics}" -- ${cur}) )\r
285 +}\r
286 +\r
287 +_notmuch_new()\r
288 +{\r
289 +    local cur prev words cword split\r
290 +    _init_completion || return\r
291 +\r
292 +    local options="--no-hooks"\r
293 +    COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )\r
294 +}\r
295 +\r
296 +_notmuch_reply()\r
297 +{\r
298 +    local cur prev words cword split\r
299 +    _init_completion -s || return\r
300 +\r
301 +    $split &&\r
302 +    case "${prev}" in\r
303 +       --format)\r
304 +           COMPREPLY=( $( compgen -W "default json sexp headers-only" -- "${cur}" ) )\r
305 +           return\r
306 +           ;;\r
307 +       --reply-to)\r
308 +           COMPREPLY=( $( compgen -W "all sender" -- "${cur}" ) )\r
309 +           return\r
310 +           ;;\r
311 +    esac\r
312 +\r
313 +    local options="--format= --format-version= --reply-to= --decrypt"\r
314 +    compopt -o nospace\r
315 +    COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
316 +}\r
317 +\r
318 +_notmuch_restore()\r
319 +{\r
320 +    local cur prev words cword split\r
321 +    _init_completion -s || return\r
322 +\r
323 +    $split &&\r
324 +    case "${prev}" in\r
325 +       --format)\r
326 +           COMPREPLY=( $( compgen -W "sup batch-tag auto" -- "${cur}" ) )\r
327 +           return\r
328 +           ;;\r
329 +    esac\r
330 +\r
331 +    local options="--format= --accumulate --input="\r
332 +    compopt -o nospace\r
333 +    COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
334 +}\r
335 +\r
336 +_notmuch_search()\r
337 +{\r
338 +    local cur prev words cword split\r
339 +    _init_completion -s || return\r
340 +\r
341 +    $split &&\r
342 +    case "${prev}" in\r
343 +       --format)\r
344 +           COMPREPLY=( $( compgen -W "json sexp text text0" -- "${cur}" ) )\r
345 +           return\r
346 +           ;;\r
347 +       --output)\r
348 +           COMPREPLY=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) )\r
349 +           return\r
350 +           ;;\r
351 +       --sort)\r
352 +           COMPREPLY=( $( compgen -W "newest-first oldest-first" -- "${cur}" ) )\r
353 +           return\r
354 +           ;;\r
355 +       --exclude)\r
356 +           COMPREPLY=( $( compgen -W "true false flag" -- "${cur}" ) )\r
357 +           return\r
358 +           ;;\r
359 +    esac\r
360 +\r
361 +    local options="--format= --output= --sort= --offset= --limit= --exclude="\r
362 +    compopt -o nospace\r
363 +    COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
364 +}\r
365 +\r
366 +# N/A\r
367 +# _notmuch_setup()\r
368 +# {\r
369 +# }\r
370 +\r
371 +_notmuch_show()\r
372 +{\r
373 +    local cur prev words cword split\r
374 +    _init_completion -s || return\r
375 +\r
376 +    $split &&\r
377 +    case "${prev}" in\r
378 +       --entire-thread)\r
379 +           COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )\r
380 +           return\r
381 +           ;;\r
382 +       --format)\r
383 +           COMPREPLY=( $( compgen -W "text json sexp mbox raw" -- "${cur}" ) )\r
384 +           return\r
385 +           ;;\r
386 +       --exclude|--body)\r
387 +           COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )\r
388 +           return\r
389 +           ;;\r
390 +    esac\r
391 +\r
392 +    local options="--entire-thread= --format= --exclude= --body= --format-version= --part= --verify --decrypt"\r
393 +    compopt -o nospace\r
394 +    COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
395 +}\r
396 +\r
397 +_notmuch_tag()\r
398 +{\r
399 +    local cur prev words cword split\r
400 +    # handle tags with colons and equal signs\r
401 +    _init_completion -n := || return\r
402 +\r
403 +    case "${cur}" in\r
404 +       +*) COMPREPLY=( $(compgen -P "+" -W "`notmuch search --output=tags \*`" -- ${cur##+}) );;\r
405 +       -*) COMPREPLY=( $(compgen -P "-" -W "`notmuch search --output=tags \*`" -- ${cur##-}) );;\r
406 +    esac\r
407 +    # handle tags with colons\r
408 +    __ltrim_colon_completions "${cur}"\r
409 +}\r
410 +\r
411 +_notmuch()\r
412 +{\r
413 +    local arg cur prev words cword split\r
414 +    _init_completion || return\r
415 +\r
416 +    COMPREPLY=()\r
417 +\r
418 +    # subcommand\r
419 +    _get_first_arg\r
420 +\r
421 +    # complete --help option like the subcommand\r
422 +    if [ -z "${arg}" -a "${prev}" = "--help" ]; then\r
423 +       arg="help"\r
424 +    fi\r
425 +\r
426 +    if [ -z "${arg}" ]; then\r
427 +       # top level completion\r
428 +       local top_options="--help --version"\r
429 +       case "${cur}" in\r
430 +           -*) COMPREPLY=( $(compgen -W "${top_options}" -- ${cur}) ) ;;\r
431 +           *) COMPREPLY=( $(compgen -W "${_notmuch_commands}" -- ${cur}) ) ;;\r
432 +       esac\r
433 +    else\r
434 +       # complete using _notmuch_subcommand if one exist\r
435 +       local completion_func="_notmuch_${arg//-/_}"\r
436 +       declare -f $completion_func >/dev/null && $completion_func\r
437 +    fi\r
438 +} &&\r
439 +complete -F _notmuch notmuch\r
440 -- \r
441 1.7.10.4\r
442 \r