X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=completion%2Fnotmuch-completion.bash;h=f94dbeed66bdef7a4f757d8cb346fa008b1e6e88;hp=8665268c789eda9b789849bf999d59f0a4f87aa3;hb=a1260896f6b2beb82f46c41663f00cb42a4c5ce7;hpb=8cbb5114a20c1217f23977fd5edca99a0b7a2955 diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index 8665268c..f94dbeed 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -1,10 +1,13 @@ -# Bash completion for notmuch +# bash completion for notmuch -*- shell-script -*- # -# Copyright © 2009 Carl Worth +# Copyright © 2013 Jani Nikula +# +# Based on the bash-completion package: +# https://github.com/scop/bash-completion # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or +# the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, @@ -13,59 +16,603 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see http://www.gnu.org/licenses/ . -# -# Author: Carl Worth -# -# Based on "notmuch help" as follows: -# -# Usage: notmuch [args...] -# -# Where and [args...] are as follows: -# -# setup -# -# new -# -# search [options] [...] +# along with this program. If not, see https://www.gnu.org/licenses/ . # -# show +# Author: Jani Nikula # -# reply # -# tag +|- [...] [--] [...] +# BUGS: # -# dump [] +# Add space after an --option without parameter (e.g. reply --decrypt) +# on completion. # -# restore -# -# help [] -_notmuch() +_notmuch_shared_options="--help --uuid= --version" + +# $1: current input of the form prefix:partialinput, where prefix is +# to or from. +_notmuch_email() { - local current previous commands help_options + local output prefix cur - previous=${COMP_WORDS[COMP_CWORD-1]} - current="${COMP_WORDS[COMP_CWORD]}" + prefix="${1%%:*}" + cur="${1#*:}" - commands="setup new search show reply tag dump restore help" - help_options="setup new search show reply tag dump restore search-terms" - search_options="--max-threads= --first= --sort=" + # Cut the input to be completed at punctuation because + # (apparently) Xapian does not support the trailing wildcard '*' + # operator for input with punctuation. We let compgen handle the + # extra filtering required. + cur="${cur%%[^a-zA-Z0-9]*}" - COMPREPLY=() + case "$prefix" in + # Note: It would be more accurate and less surprising to have + # output=recipients here for to: addresses, but as gathering + # the recipient addresses requires disk access for each + # matching message, this becomes prohibitively slow. + to|from) output=sender;; + *) return;; + esac + + # Only emit plain, lower case, unique addresses. + notmuch address --output=$output $prefix:"${cur}*" | \ + sed 's/[^<]*<\([^>]*\)>/\1/' | tr "[:upper:]" "[:lower:]" | sort -u +} + +_notmuch_mimetype() +{ + # use mime types from mime-support package if available, and fall + # back to a handful of common ones otherwise + if [ -r "/etc/mime.types" ]; then + sed -n '/^[[:alpha:]]/{s/[[:space:]].*//;p;}' /etc/mime.types + else + cat </dev/null 2>&1 || return + + _init_completion || return + + COMPREPLY=() + + # subcommand + _get_first_arg + + # complete --help option like the subcommand + if [ -z "${arg}" -a "${prev}" = "--help" ]; then + arg="help" + fi + + if [ -z "${arg}" ]; then + # top level completion + case "${cur}" in + -*) + # XXX: handle ${_notmuch_shared_options} and --config= + local options="--help --version" + COMPREPLY=( $(compgen -W "${options}" -- ${cur}) ) + ;; + *) + COMPREPLY=( $(compgen -W "${_notmuch_commands}" -- ${cur}) ) + ;; + esac + elif [ "${arg}" = "help" ]; then + # handle help command specially due to _notmuch_commands usage + local help_topics="$_notmuch_commands hooks search-terms" + COMPREPLY=( $(compgen -W "${help_topics}" -- ${cur}) ) + else + # complete using _notmuch_subcommand if one exist + local completion_func="_notmuch_${arg//-/_}" + declare -f $completion_func >/dev/null && $completion_func + fi +} && +complete -F _notmuch notmuch