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 978A6431FD2 for ; Tue, 27 Jan 2015 11:48:35 -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 AwuNpSZFspjv for ; Tue, 27 Jan 2015 11:48:32 -0800 (PST) Received: from mail-we0-f177.google.com (mail-we0-f177.google.com [74.125.82.177]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 29F11431FD9 for ; Tue, 27 Jan 2015 11:48:18 -0800 (PST) Received: by mail-we0-f177.google.com with SMTP id l61so16823263wev.8 for ; Tue, 27 Jan 2015 11:48:16 -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:in-reply-to :references; bh=nVNvqY03ODraSJk5c24gwxvw3/U7rRdhTJQQ6EKwvGE=; b=c6QwIBM1s7KGNsdMKN1/eyLRaWp8LLgnBJ/I3RzGyoWSQyH9LHSXEF1tSycugL+Bnm eq+aqZUDioPLzHgVvN3+Lt7LitGWawsKjXMkw581y+/0koETDX5We3ILagb3dAB5D/e3 u1vjFlVSAslTmlRL2ZS/njCpHCFIUtSXAWzST7alyygQ8oaNHd0wVBy5bklKl2URzpcO UR5TfUEZa+bnZ4Veo13WaVeZuTMn/l/El9SSdKPKr5DepRwJt+6cYGuWduL2F5V8sjQM iOZFJN0dO8cPAdkTzgihnP5c4EspB5gwIzVUmtRF2qpqTps0PdhhHyd7VNMSMIstOeA4 NTEw== X-Gm-Message-State: ALoCoQmvvpl6RvPEhjUausb07QM/x80BD06Q3FQfDRRvYC7/xC/CnMJhiv9DX0veyz8KCd4wi3Vj X-Received: by 10.194.190.162 with SMTP id gr2mr1249168wjc.13.1422388095900; Tue, 27 Jan 2015 11:48:15 -0800 (PST) Received: from localhost (mobile-internet-5d6ab0-235.dhcp.inet.fi. [93.106.176.235]) by mx.google.com with ESMTPSA id v7sm19439267wib.5.2015.01.27.11.48.14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Jan 2015 11:48:15 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH 5/5] completion: complete addresses in from:/to: search terms Date: Tue, 27 Jan 2015 21:48:18 +0200 Message-Id: <1422388098-16333-5-git-send-email-jani@nikula.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1422388098-16333-1-git-send-email-jani@nikula.org> References: <1422388098-16333-1-git-send-email-jani@nikula.org> 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: Tue, 27 Jan 2015 19:48:36 -0000 Use the new notmuch address command to do completion for addresses in from: and to:. --- This patch is more of an RFC. The to: completion is sloooow because typically there are more matches to begin with, and then producing the results requires reading the messages. Maybe it would be better to use the same mechanism as from: for both, even if it's not accurate for to:? --- completion/notmuch-completion.bash | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index e0498903f22f..db49294fc58c 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -27,10 +27,30 @@ # 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 + to) output=recipients;; + 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 +64,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