X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=completion%2Fnotmuch-completion.bash;h=d44b2a2811f016ce052296f61a8c12bbc77cf3d8;hp=386437333742cbc887d92a851d37a2a438d6b684;hb=4d486cf94d3fcfe4f07daf7dc65c9de04c7cfdd5;hpb=516a1b37b6a5c1c8bf7b262250e14290513bb0ba diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index 38643733..d44b2a28 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() { - notmuch config get user.primary_email - notmuch config get user.other_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() +{ + # 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 <