[PATCH] completion: load all addresses and cache in _email-notmuch

Vincent Breitmoser look at my.amazin.horse
Mon Sep 17 14:12:36 PDT 2018


This loads all known email addresses for completion, and caches the
result. The cache validity is based on `notmuch count --lastmod
mid:nonexistent`.
---
 completion/zsh/_email-notmuch | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/completion/zsh/_email-notmuch b/completion/zsh/_email-notmuch
index 291c2358..89dfd414 100644
--- a/completion/zsh/_email-notmuch
+++ b/completion/zsh/_email-notmuch
@@ -2,8 +2,14 @@
 
 local expl
 local -a notmuch_addr
+local notmuch_addr_lastmod
+local lastmod=( ${(f)"$(notmuch count --lastmod mid:nonexistent)"} )
 
-notmuch_addr=( ${(f)"$(notmuch address --deduplicate=address --output=address -- $PREFIX'*')"} )
+if ! _retrieve_cache notmuch-addresses || [[ $lastmod != $notmuch_addr_lastmod ]]; then
+  notmuch_addr_lastmod=$lastmod
+  notmuch_addr=( ${(f)"$(notmuch address --deduplicate=address --output=address -- '*')"} )
+  _store_cache notmuch-addresses notmuch_addr notmuch_addr_lastmod
+fi
 
 _description notmuch-addr expl 'email address (notmuch)'
 compadd "$expl[@]" -a notmuch_addr
-- 
2.18.0



More information about the notmuch mailing list