X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=completion%2Fnotmuch-completion.bash;h=f94dbeed66bdef7a4f757d8cb346fa008b1e6e88;hp=0f132043dea5e89219f6853714b63c74ac101476;hb=a1260896f6b2beb82f46c41663f00cb42a4c5ce7;hpb=957fc2e1a7d00636c7eaaf487edae65e7a63dc8f diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index 0f132043..f94dbeed 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -3,7 +3,7 @@ # Copyright © 2013 Jani Nikula # # Based on the bash-completion package: -# http://bash-completion.alioth.debian.org/ +# 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 @@ -16,7 +16,7 @@ # 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/ . +# along with this program. If not, see https://www.gnu.org/licenses/ . # # Author: Jani Nikula # @@ -27,10 +27,63 @@ # on completion. # -_notmuch_user_emails() +_notmuch_shared_options="--help --uuid= --version" + +# $1: current input of the form prefix:partialinput, where prefix is +# to or from. +_notmuch_email() +{ + local output prefix cur + + prefix="${1%%:*}" + cur="${1#*:}" + + # 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]*}" + + 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() { - notmuch config get user.primary_email - notmuch config get user.other_email + # 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=() @@ -398,10 +595,15 @@ _notmuch() if [ -z "${arg}" ]; then # top level completion - local top_options="--help --version" case "${cur}" in - -*) COMPREPLY=( $(compgen -W "${top_options}" -- ${cur}) ) ;; - *) COMPREPLY=( $(compgen -W "${_notmuch_commands}" -- ${cur}) ) ;; + -*) + # 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