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: 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
199 local options="--create-folder --folder="
201 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
205 COMPREPLY=( $(compgen -P "+" -W "`notmuch search --output=tags \*`" -- ${cur##+}) )
208 COMPREPLY=( $(compgen -P "-" -W "`notmuch search --output=tags \*`" -- ${cur##-}) )
211 # handle tags with colons
212 __ltrim_colon_completions "${cur}"
217 local cur prev words cword split
218 _init_completion || return
222 local options="--no-hooks --quiet"
223 COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
230 local cur prev words cword split
231 _init_completion -s || return
236 COMPREPLY=( $( compgen -W "default json sexp headers-only" -- "${cur}" ) )
240 COMPREPLY=( $( compgen -W "all sender" -- "${cur}" ) )
248 local options="--format= --format-version= --reply-to= --decrypt"
250 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
253 _notmuch_search_terms
260 local cur prev words cword split
261 _init_completion -s || return
266 COMPREPLY=( $( compgen -W "sup batch-tag auto" -- "${cur}" ) )
278 local options="--format= --accumulate --input="
280 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
287 local cur prev words cword split
288 _init_completion -s || return
293 COMPREPLY=( $( compgen -W "json sexp text text0" -- "${cur}" ) )
297 COMPREPLY=( $( compgen -W "summary threads messages files tags sender recipients" -- "${cur}" ) )
301 COMPREPLY=( $( compgen -W "newest-first oldest-first" -- "${cur}" ) )
305 COMPREPLY=( $( compgen -W "true false flag all" -- "${cur}" ) )
313 local options="--format= --output= --sort= --offset= --limit= --exclude= --duplicate="
315 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
318 _notmuch_search_terms
325 local cur prev words cword split
326 _init_completion -s || return
331 COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
335 COMPREPLY=( $( compgen -W "text json sexp mbox raw" -- "${cur}" ) )
339 COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
347 local options="--entire-thread= --format= --exclude= --body= --format-version= --part= --verify --decrypt --include-html"
349 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
352 _notmuch_search_terms
359 local cur prev words cword split
360 # handle tags with colons and equal signs
361 _init_completion -s -n := || return
374 local options="--batch --input= --remove-all"
376 COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
380 COMPREPLY=( $(compgen -P "+" -W "`notmuch search --output=tags \*`" -- ${cur##+}) )
383 COMPREPLY=( $(compgen -P "-" -W "`notmuch search --output=tags \*`" -- ${cur##-}) )
386 _notmuch_search_terms
390 # handle tags with colons
391 __ltrim_colon_completions "${cur}"
396 local _notmuch_commands="compact config count dump help insert new reply restore search setup show tag"
397 local arg cur prev words cword split
399 # require bash-completion with _init_completion
400 type -t _init_completion >/dev/null 2>&1 || return
402 _init_completion || return
409 # complete --help option like the subcommand
410 if [ -z "${arg}" -a "${prev}" = "--help" ]; then
414 if [ -z "${arg}" ]; then
415 # top level completion
416 local top_options="--help --version"
418 -*) COMPREPLY=( $(compgen -W "${top_options}" -- ${cur}) ) ;;
419 *) COMPREPLY=( $(compgen -W "${_notmuch_commands}" -- ${cur}) ) ;;
421 elif [ "${arg}" = "help" ]; then
422 # handle help command specially due to _notmuch_commands usage
423 local help_topics="$_notmuch_commands hooks search-terms"
424 COMPREPLY=( $(compgen -W "${help_topics}" -- ${cur}) )
426 # complete using _notmuch_subcommand if one exist
427 local completion_func="_notmuch_${arg//-/_}"
428 declare -f $completion_func >/dev/null && $completion_func
431 complete -F _notmuch notmuch