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 path=`notmuch config get database.path`
55 COMPREPLY=( $(compgen -d "$path/${cur##path:}" | sed "s|^$path/||" ) )
58 local path=`notmuch config get database.path`
60 COMPREPLY=( $(compgen -d "$path/${cur##folder:}" | \
61 sed "s|^$path/||" | grep -v "\(^\|/\)\(cur\|new\|tmp\)$" ) )
64 local search_terms="from: to: subject: attachment: mimetype: tag: id: thread: folder: path: date:"
66 COMPREPLY=( $(compgen -W "${search_terms}" -- ${cur}) )
69 # handle search prefixes and tags with colons
70 __ltrim_colon_completions "${cur}"
75 local cur prev words cword split
76 _init_completion -s || return
89 local options="--backup= --quiet"
91 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
98 local cur prev words cword split
99 _init_completion || return
103 COMPREPLY=( $(compgen -W "get set list" -- ${cur}) )
106 COMPREPLY=( $(compgen -W "`notmuch config list | sed 's/=.*\$//'`" -- ${cur}) )
108 # these will also complete on config get, but we don't care
112 maildir.synchronize_flags)
113 COMPREPLY=( $(compgen -W "true false" -- ${cur}) )
120 local cur prev words cword split
121 _init_completion -s || return
126 COMPREPLY=( $( compgen -W "messages threads files" -- "${cur}" ) )
130 COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
142 local options="--output= --exclude= --batch --input="
144 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
147 _notmuch_search_terms
154 local cur prev words cword split
155 _init_completion -s || return
160 COMPREPLY=( $( compgen -W "sup batch-tag" -- "${cur}" ) )
172 local options="--format= --output="
174 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
177 _notmuch_search_terms
184 local cur prev words cword split
185 # handle tags with colons and equal signs
186 _init_completion -s -n := || return
191 local path=`notmuch config get database.path`
193 COMPREPLY=( $(compgen -d "$path/${cur}" | \
194 sed "s|^$path/||" | grep -v "\(^\|/\)\(cur\|new\|tmp\)$" ) )
202 local options="--create-folder --folder= --keep --no-hooks"
204 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
208 COMPREPLY=( $(compgen -P "+" -W "`notmuch search --output=tags \*`" -- ${cur##+}) )
211 COMPREPLY=( $(compgen -P "-" -W "`notmuch search --output=tags \*`" -- ${cur##-}) )
214 # handle tags with colons
215 __ltrim_colon_completions "${cur}"
220 local cur prev words cword split
221 _init_completion || return
225 local options="--no-hooks --quiet"
226 COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
233 local cur prev words cword split
234 _init_completion -s || return
239 COMPREPLY=( $( compgen -W "default json sexp headers-only" -- "${cur}" ) )
243 COMPREPLY=( $( compgen -W "all sender" -- "${cur}" ) )
251 local options="--format= --format-version= --reply-to= --decrypt"
253 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
256 _notmuch_search_terms
263 local cur prev words cword split
264 _init_completion -s || return
269 COMPREPLY=( $( compgen -W "sup batch-tag auto" -- "${cur}" ) )
281 local options="--format= --accumulate --input="
283 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
290 local cur prev words cword split
291 _init_completion -s || return
296 COMPREPLY=( $( compgen -W "json sexp text text0" -- "${cur}" ) )
300 COMPREPLY=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) )
304 COMPREPLY=( $( compgen -W "newest-first oldest-first" -- "${cur}" ) )
308 COMPREPLY=( $( compgen -W "true false flag all" -- "${cur}" ) )
316 local options="--format= --output= --sort= --offset= --limit= --exclude= --duplicate="
318 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
321 _notmuch_search_terms
328 local cur prev words cword split
329 _init_completion -s || return
334 COMPREPLY=( $( compgen -W "json sexp text text0" -- "${cur}" ) )
338 COMPREPLY=( $( compgen -W "sender recipients count" -- "${cur}" ) )
342 COMPREPLY=( $( compgen -W "newest-first oldest-first" -- "${cur}" ) )
346 COMPREPLY=( $( compgen -W "true false flag all" -- "${cur}" ) )
354 local options="--format= --output= --sort= --exclude="
356 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
359 _notmuch_search_terms
366 local cur prev words cword split
367 _init_completion -s || return
372 COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
376 COMPREPLY=( $( compgen -W "text json sexp mbox raw" -- "${cur}" ) )
380 COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
388 local options="--entire-thread= --format= --exclude= --body= --format-version= --part= --verify --decrypt --include-html"
390 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
393 _notmuch_search_terms
400 local cur prev words cword split
401 # handle tags with colons and equal signs
402 _init_completion -s -n := || return
415 local options="--batch --input= --remove-all"
417 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
421 COMPREPLY=( $(compgen -P "+" -W "`notmuch search --output=tags \*`" -- ${cur##+}) )
424 COMPREPLY=( $(compgen -P "-" -W "`notmuch search --output=tags \*`" -- ${cur##-}) )
427 _notmuch_search_terms
431 # handle tags with colons
432 __ltrim_colon_completions "${cur}"
437 local _notmuch_commands="compact config count dump help insert new reply restore search address setup show tag"
438 local arg cur prev words cword split
440 # require bash-completion with _init_completion
441 type -t _init_completion >/dev/null 2>&1 || return
443 _init_completion || return
450 # complete --help option like the subcommand
451 if [ -z "${arg}" -a "${prev}" = "--help" ]; then
455 if [ -z "${arg}" ]; then
456 # top level completion
457 local top_options="--help --version"
459 -*) COMPREPLY=( $(compgen -W "${top_options}" -- ${cur}) ) ;;
460 *) COMPREPLY=( $(compgen -W "${_notmuch_commands}" -- ${cur}) ) ;;
462 elif [ "${arg}" = "help" ]; then
463 # handle help command specially due to _notmuch_commands usage
464 local help_topics="$_notmuch_commands hooks search-terms"
465 COMPREPLY=( $(compgen -W "${help_topics}" -- ${cur}) )
467 # complete using _notmuch_subcommand if one exist
468 local completion_func="_notmuch_${arg//-/_}"
469 declare -f $completion_func >/dev/null && $completion_func
472 complete -F _notmuch notmuch