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 || return
69 COMPREPLY=( $(compgen -W "get set list" -- ${cur}) )
72 COMPREPLY=( $(compgen -W "`notmuch config list | sed 's/=.*\$//'`" -- ${cur}) )
74 # these will also complete on config get, but we don't care
78 maildir.synchronize_flags)
79 COMPREPLY=( $(compgen -W "true false" -- ${cur}) )
86 local cur prev words cword split
87 _init_completion -s || return
92 COMPREPLY=( $( compgen -W "messages threads" -- "${cur}" ) )
96 COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
104 local options="--output= --exclude="
106 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
109 _notmuch_search_terms
116 local cur prev words cword split
117 _init_completion -s || return
122 COMPREPLY=( $( compgen -W "sup batch-tag" -- "${cur}" ) )
134 local options="--format= --output="
136 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
139 _notmuch_search_terms
146 local cur prev words cword split
147 _init_completion || return
151 local options="--no-hooks"
152 COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
159 local cur prev words cword split
160 _init_completion -s || return
165 COMPREPLY=( $( compgen -W "default json sexp headers-only" -- "${cur}" ) )
169 COMPREPLY=( $( compgen -W "all sender" -- "${cur}" ) )
177 local options="--format= --format-version= --reply-to= --decrypt"
179 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
182 _notmuch_search_terms
189 local cur prev words cword split
190 _init_completion -s || return
195 COMPREPLY=( $( compgen -W "sup batch-tag auto" -- "${cur}" ) )
207 local options="--format= --accumulate --input="
209 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
216 local cur prev words cword split
217 _init_completion -s || return
222 COMPREPLY=( $( compgen -W "json sexp text text0" -- "${cur}" ) )
226 COMPREPLY=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) )
230 COMPREPLY=( $( compgen -W "newest-first oldest-first" -- "${cur}" ) )
234 COMPREPLY=( $( compgen -W "true false flag" -- "${cur}" ) )
242 local options="--format= --output= --sort= --offset= --limit= --exclude="
244 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
247 _notmuch_search_terms
254 local cur prev words cword split
255 _init_completion -s || return
260 COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
264 COMPREPLY=( $( compgen -W "text json sexp mbox raw" -- "${cur}" ) )
268 COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
276 local options="--entire-thread= --format= --exclude= --body= --format-version= --part= --verify --decrypt"
278 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
281 _notmuch_search_terms
288 local cur prev words cword split
289 # handle tags with colons and equal signs
290 _init_completion -n := || return
294 COMPREPLY=( $(compgen -P "+" -W "`notmuch search --output=tags \*`" -- ${cur##+}) )
297 COMPREPLY=( $(compgen -P "-" -W "`notmuch search --output=tags \*`" -- ${cur##-}) )
300 _notmuch_search_terms
304 # handle tags with colons
305 __ltrim_colon_completions "${cur}"
310 local _notmuch_commands="config count dump help new reply restore search setup show tag"
311 local arg cur prev words cword split
312 _init_completion || return
319 # complete --help option like the subcommand
320 if [ -z "${arg}" -a "${prev}" = "--help" ]; then
324 if [ -z "${arg}" ]; then
325 # top level completion
326 local top_options="--help --version"
328 -*) COMPREPLY=( $(compgen -W "${top_options}" -- ${cur}) ) ;;
329 *) COMPREPLY=( $(compgen -W "${_notmuch_commands}" -- ${cur}) ) ;;
331 elif [ "${arg}" = "help" ]; then
332 # handle help command specially due to _notmuch_commands usage
333 local help_topics="$_notmuch_commands hooks search-terms"
334 COMPREPLY=( $(compgen -W "${help_topics}" -- ${cur}) )
336 # complete using _notmuch_subcommand if one exist
337 local completion_func="_notmuch_${arg//-/_}"
338 declare -f $completion_func >/dev/null && $completion_func
341 complete -F _notmuch notmuch