X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=completion%2Fnotmuch-completion.bash;h=7aae4297ae0e1fecdbff7f97c857fff3529efcac;hp=0571dc9da8e332b3fa3c24ab27e9fa61a3c637f4;hb=81168917447a582aee186fc0edc09f5277ce565d;hpb=523f06a0add737aa0577f43c319f069bc0ff10f3 diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index 0571dc9d..7aae4297 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 <