1 # bash completion for notmuch -*- shell-script -*-
3 # Copyright © 2013 Jani Nikula
5 # Based on the bash-completion package:
6 # http://bash-completion.alioth.debian.org/
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see http://www.gnu.org/licenses/ .
21 # Author: Jani Nikula <jani@nikula.org>
26 # Add space after an --option without parameter (e.g. reply --decrypt)
30 _notmuch_user_emails()
32 notmuch config get user.primary_email
33 notmuch config get user.other_email
36 _notmuch_search_terms()
38 local cur prev words cword split
39 # handle search prefixes and tags with colons and equal signs
40 _init_completion -n := || return
44 COMPREPLY=( $(compgen -P "tag:" -W "`notmuch search --output=tags \*`" -- ${cur##tag:}) )
47 COMPREPLY=( $(compgen -P "to:" -W "`_notmuch_user_emails`" -- ${cur##to:}) )
50 COMPREPLY=( $(compgen -P "from:" -W "`_notmuch_user_emails`" -- ${cur##from:}) )
53 local search_terms="from: to: subject: attachment: tag: id: thread: folder: date:"
55 COMPREPLY=( $(compgen -W "${search_terms}" -- ${cur}) )
58 # handle search prefixes and tags with colons
59 __ltrim_colon_completions "${cur}"
64 local cur prev words cword split
65 _init_completion -s || return
78 local options="--backup= --quiet"
80 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
87 local cur prev words cword split
88 _init_completion || return
92 COMPREPLY=( $(compgen -W "get set list" -- ${cur}) )
95 COMPREPLY=( $(compgen -W "`notmuch config list | sed 's/=.*\$//'`" -- ${cur}) )
97 # these will also complete on config get, but we don't care
101 maildir.synchronize_flags)
102 COMPREPLY=( $(compgen -W "true false" -- ${cur}) )
109 local cur prev words cword split
110 _init_completion -s || return
115 COMPREPLY=( $( compgen -W "messages threads files" -- "${cur}" ) )
119 COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
131 local options="--output= --exclude= --batch --input="
133 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
136 _notmuch_search_terms
143 local cur prev words cword split
144 _init_completion -s || return
149 COMPREPLY=( $( compgen -W "sup batch-tag" -- "${cur}" ) )
161 local options="--format= --output="
163 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
166 _notmuch_search_terms
173 local cur prev words cword split
174 # handle tags with colons and equal signs
175 _init_completion -s -n := || return
188 local options="--create-folder --folder="
190 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
194 COMPREPLY=( $(compgen -P "+" -W "`notmuch search --output=tags \*`" -- ${cur##+}) )
197 COMPREPLY=( $(compgen -P "-" -W "`notmuch search --output=tags \*`" -- ${cur##-}) )
200 # handle tags with colons
201 __ltrim_colon_completions "${cur}"
206 local cur prev words cword split
207 _init_completion || return
211 local options="--no-hooks"
212 COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
219 local cur prev words cword split
220 _init_completion -s || return
225 COMPREPLY=( $( compgen -W "default json sexp headers-only" -- "${cur}" ) )
229 COMPREPLY=( $( compgen -W "all sender" -- "${cur}" ) )
237 local options="--format= --format-version= --reply-to= --decrypt"
239 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
242 _notmuch_search_terms
249 local cur prev words cword split
250 _init_completion -s || return
255 COMPREPLY=( $( compgen -W "sup batch-tag auto" -- "${cur}" ) )
267 local options="--format= --accumulate --input="
269 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
276 local cur prev words cword split
277 _init_completion -s || return
282 COMPREPLY=( $( compgen -W "json sexp text text0" -- "${cur}" ) )
286 COMPREPLY=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) )
290 COMPREPLY=( $( compgen -W "newest-first oldest-first" -- "${cur}" ) )
294 COMPREPLY=( $( compgen -W "true false flag all" -- "${cur}" ) )
302 local options="--format= --output= --sort= --offset= --limit= --exclude= --duplicate="
304 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
307 _notmuch_search_terms
314 local cur prev words cword split
315 _init_completion -s || return
320 COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
324 COMPREPLY=( $( compgen -W "text json sexp mbox raw" -- "${cur}" ) )
328 COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
336 local options="--entire-thread= --format= --exclude= --body= --format-version= --part= --verify --decrypt --include-html"
338 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
341 _notmuch_search_terms
348 local cur prev words cword split
349 # handle tags with colons and equal signs
350 _init_completion -s -n := || return
363 local options="--batch --input= --remove-all"
365 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
369 COMPREPLY=( $(compgen -P "+" -W "`notmuch search --output=tags \*`" -- ${cur##+}) )
372 COMPREPLY=( $(compgen -P "-" -W "`notmuch search --output=tags \*`" -- ${cur##-}) )
375 _notmuch_search_terms
379 # handle tags with colons
380 __ltrim_colon_completions "${cur}"
385 local _notmuch_commands="compact config count dump help insert new reply restore search setup show tag"
386 local arg cur prev words cword split
387 _init_completion || return
394 # complete --help option like the subcommand
395 if [ -z "${arg}" -a "${prev}" = "--help" ]; then
399 if [ -z "${arg}" ]; then
400 # top level completion
401 local top_options="--help --version"
403 -*) COMPREPLY=( $(compgen -W "${top_options}" -- ${cur}) ) ;;
404 *) COMPREPLY=( $(compgen -W "${_notmuch_commands}" -- ${cur}) ) ;;
406 elif [ "${arg}" = "help" ]; then
407 # handle help command specially due to _notmuch_commands usage
408 local help_topics="$_notmuch_commands hooks search-terms"
409 COMPREPLY=( $(compgen -W "${help_topics}" -- ${cur}) )
411 # complete using _notmuch_subcommand if one exist
412 local completion_func="_notmuch_${arg//-/_}"
413 declare -f $completion_func >/dev/null && $completion_func
416 complete -F _notmuch notmuch