[PATCH] completion: Add support for custom header prefixes

Subject: [PATCH] completion: Add support for custom header prefixes

Date: Tue, 16 Jan 2024 18:07:54 +0000

To: notmuch@notmuchmail.org

Cc:

From: Per Modin


Append custom search query prefixes, if any, to the standard set of
terms used for searching. Applies to both bash and zsh, and is checked
with Awk and GNU Awk.
---
 completion/notmuch-completion.bash | 4 ++++
 completion/zsh/_notmuch            | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
index 3748846e..cb363719 100644
--- a/completion/notmuch-completion.bash
+++ b/completion/notmuch-completion.bash
@@ -123,6 +123,10 @@ _notmuch_search_terms()
 	    ;;
 	*)
 	    local search_terms="from: to: subject: attachment: mimetype: tag: id: thread: folder: path: date: lastmod: query: property:"
+
+	    # append custom search terms, if any
+	    search_terms="${search_terms}$(notmuch config list | awk -F'[.=]' '/index\.header\./ { printf " %s:", $3 }')"
+
 	    compopt -o nospace
 	    COMPREPLY=( $(compgen -W "${search_terms}" -- ${cur}) )
 	    ;;
diff --git a/completion/zsh/_notmuch b/completion/zsh/_notmuch
index 0bdd7f77..d779ceb5 100644
--- a/completion/zsh/_notmuch
+++ b/completion/zsh/_notmuch
@@ -112,6 +112,9 @@ _notmuch_search_term() {
     'from' 'to' 'subject' 'attachment' 'mimetype' 'tag' 'id' 'thread' 'path' 'folder' 'date' 'lastmod' 'query' 'property'
   )
 
+  # append custom search terms, if any
+  notmuch_search_terms+=("${(@f)$(notmuch config list | awk -F'[.=]' '/index\.header\./ { print $3 }')}")
+
   if compset -P '(#b)([^:]#):'; then
     if (( $+functions[_notmuch_term_$match[1]] )); then
       _notmuch_term_$match[1] && ret=0
-- 
2.43.0

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: