aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorBence Ferdinandy <bence@ferdinandy.com>2024-04-13 21:51:56 +0200
committerRobin Jarry <robin@jarry.cc>2024-04-14 11:51:02 +0200
commit4d95c5371ecc4d667652bb0f5df43c68823ed08b (patch)
tree803d0c994492579fdacac8fc7a84640807393016 /commands
parent939000ccf2c3e54d1d50d3ae3f5b4e06a3fa3b69 (diff)
downloadaerc-4d95c5371ecc4d667652bb0f5df43c68823ed08b.tar.gz
query: add completions for notmuch search-terms
Add completions to :query for the notmuch search terms. Most search terms that seemed valid for interactive use in aerc are listed as options. Some of them (from, to, tag, path, and folder) get actual completions. The function was designed, so later patches can reuse it to add completions to :cf, :filter and :search for notmuch accounts. References: https://todo.sr.ht/~rjarry/aerc/244 Changelog-added: Notmuch search term completions to `:query`. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Tested-by: Julio B <julio.bacel@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r--commands/account/query.go60
-rw-r--r--commands/completion_helpers.go2
2 files changed, 60 insertions, 2 deletions
diff --git a/commands/account/query.go b/commands/account/query.go
index fccdc756..65c3c3a8 100644
--- a/commands/account/query.go
+++ b/commands/account/query.go
@@ -3,6 +3,7 @@ package account
import (
"errors"
"reflect"
+ "strings"
"time"
"git.sr.ht/~rjarry/aerc/app"
@@ -14,7 +15,7 @@ import (
type Query struct {
Account string `opt:"-a" complete:"CompleteAccount"`
Name string `opt:"-n"`
- Query string `opt:"..."`
+ Query string `opt:"..." complete:"CompleteNotmuch"`
}
func init() {
@@ -65,3 +66,60 @@ func (q Query) Execute([]string) error {
acct.Directories().Open(name, q.Query, 0*time.Second, finalize)
return nil
}
+
+func (*Query) CompleteNotmuch(arg string) []string {
+ return handleNotmuchComplete(arg)
+}
+
+var notmuch_search_terms = []string{
+ "from:",
+ "to:",
+ "tag:",
+ "date:",
+ "attachment:",
+ "mimetype:",
+ "subject:",
+ "body:",
+ "id:",
+ "thread:",
+ "folder:",
+ "path:",
+}
+
+func handleNotmuchComplete(arg string) []string {
+ prefixes := []string{"from:", "to:"}
+ for _, prefix := range prefixes {
+ if strings.HasPrefix(arg, prefix) {
+ arg = strings.TrimPrefix(arg, prefix)
+ return commands.FilterList(
+ commands.GetAddress(arg), arg,
+ func(v string) string { return prefix + v },
+ )
+ }
+ }
+
+ prefixes = []string{"tag:"}
+ for _, prefix := range prefixes {
+ if strings.HasPrefix(arg, prefix) {
+ arg = strings.TrimPrefix(arg, prefix)
+ return commands.FilterList(
+ commands.GetLabels(arg), arg,
+ func(v string) string { return prefix + v },
+ )
+ }
+ }
+
+ prefixes = []string{"path:", "folder:"}
+ dbPath := strings.TrimPrefix(app.SelectedAccount().AccountConfig().Source, "notmuch://")
+ for _, prefix := range prefixes {
+ if strings.HasPrefix(arg, prefix) {
+ arg = strings.TrimPrefix(arg, prefix)
+ return commands.FilterList(
+ commands.CompletePath(dbPath+arg, true), arg,
+ func(v string) string { return prefix + strings.TrimPrefix(v, dbPath) },
+ )
+ }
+ }
+
+ return commands.FilterList(notmuch_search_terms, arg, nil)
+}
diff --git a/commands/completion_helpers.go b/commands/completion_helpers.go
index 02c13526..7f046630 100644
--- a/commands/completion_helpers.go
+++ b/commands/completion_helpers.go
@@ -29,7 +29,7 @@ func GetAddress(search string) []string {
log.Warnf("could not complete header: %v", err)
})
- if len(search) > config.Ui.CompletionMinChars && cmpl != nil {
+ if cmpl != nil {
addrList, _ := cmpl.ForHeader("to")(search)
for _, full := range addrList {
addr, err := mail.ParseAddress(full)