From: Jani Nikula Date: Sat, 7 Mar 2015 12:44:42 +0000 (+0200) Subject: [PATCH] completion: complete addresses in from:/to: search terms X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c5e052828f9b82828973f66ed5c4d4523052dc35;p=notmuch-archives.git [PATCH] completion: complete addresses in from:/to: search terms --- diff --git a/9b/b13977f91ade1abb2649c8e49c3b4a4f53fbd0 b/9b/b13977f91ade1abb2649c8e49c3b4a4f53fbd0 new file mode 100644 index 000000000..dc9edeb95 --- /dev/null +++ b/9b/b13977f91ade1abb2649c8e49c3b4a4f53fbd0 @@ -0,0 +1,134 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 06892431FBC + for ; Sat, 7 Mar 2015 04:44:31 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 1.738 +X-Spam-Level: * +X-Spam-Status: No, score=1.738 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id OzwW4heQ4gAM for ; + Sat, 7 Mar 2015 04:44:26 -0800 (PST) +Received: from mail-we0-f176.google.com (mail-we0-f176.google.com + [74.125.82.176]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 0BDCA431FAE + for ; Sat, 7 Mar 2015 04:44:26 -0800 (PST) +Received: by wesx3 with SMTP id x3so17973591wes.4 + for ; Sat, 07 Mar 2015 04:44:24 -0800 (PST) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id; + bh=YiCgrK88aWn9FyKle7pTCeKzMQI38fShBtBTLKga/iY=; + b=LLwF+TdR0S3fUmkz+58y0GIQOhbwSvpazlswbQFoe1o0GAmiwjmuePZvPhxTxaE+vy + udTTSxk3O30m48Put/92w5epMAlYgiJIk5jsmydu8eSSjKmc/QMFQLohzc13ak1GMCkr + zmfz1YJl87jN44jRwROsRje2UY8QWPgtYQv2KTva/weUZGYv0PuHAlLZe+iytTgQlvPZ + 1JWgebmyzIVAYm/nsuenIZ0kZ8yLKb37Vwa7sih4y8yyDuzLCm6y/+xLrvY7rd4MF8r1 + a0rqQcDU1bc3bzDbE4kC/5tH10qnf7ssAzpykRttz75mI5cGdCEvX3v7g7Hgo86mA1ww + xnVg== +X-Gm-Message-State: + ALoCoQnYoc3zR4iS3zRKQixQK4xGXX7/YRrmQ3KZ02qjCK3GKyxc6af08D7nhMyvmhutLgvTXcbT +X-Received: by 10.180.20.177 with SMTP id o17mr83436757wie.66.1425732263909; + Sat, 07 Mar 2015 04:44:23 -0800 (PST) +Received: from localhost (mobile-internet-bcee3b-76.dhcp.inet.fi. + [188.238.59.76]) by mx.google.com with ESMTPSA id + pp10sm17701351wjc.31.2015.03.07.04.44.22 + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Sat, 07 Mar 2015 04:44:22 -0800 (PST) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH] completion: complete addresses in from:/to: search terms +Date: Sat, 7 Mar 2015 14:44:42 +0200 +Message-Id: <1425732282-1113-1-git-send-email-jani@nikula.org> +X-Mailer: git-send-email 2.1.4 +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 07 Mar 2015 12:44:31 -0000 + +Use the new notmuch address command to do completion for addresses in +from: and to:. Use --output=sender for both for efficiency, even +though --output=recipients would be more accurate for to: prefix +completion. + +--- + +This is v2 of id:1422388098-16333-5-git-send-email-jani@nikula.org +opting for --output=sender for both to: and from:. Added a comment to +point this out. +--- + completion/notmuch-completion.bash | 33 ++++++++++++++++++++++++++++----- + 1 file changed, 28 insertions(+), 5 deletions(-) + +diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash +index e0498903f22f..960275d1f672 100644 +--- a/completion/notmuch-completion.bash ++++ b/completion/notmuch-completion.bash +@@ -27,10 +27,33 @@ + # on completion. + # + +-_notmuch_user_emails() ++# $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_search_terms() +@@ -44,10 +67,10 @@ _notmuch_search_terms() + COMPREPLY=( $(compgen -P "tag:" -W "`notmuch search --output=tags \*`" -- ${cur##tag:}) ) + ;; + to:*) +- COMPREPLY=( $(compgen -P "to:" -W "`_notmuch_user_emails`" -- ${cur##to:}) ) ++ COMPREPLY=( $(compgen -P "to:" -W "`_notmuch_email ${cur}`" -- ${cur##to:}) ) + ;; + from:*) +- COMPREPLY=( $(compgen -P "from:" -W "`_notmuch_user_emails`" -- ${cur##from:}) ) ++ COMPREPLY=( $(compgen -P "from:" -W "`_notmuch_email ${cur}`" -- ${cur##from:}) ) + ;; + path:*) + local path=`notmuch config get database.path` +-- +2.1.4 +