summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2019-12-21 16:21:27 +0100
committerDrew DeVault <sir@cmpwn.com>2019-12-21 11:20:12 -0500
commit00263bf8668130abb4aa5ac3383aeb9865e71328 (patch)
tree5db84bafed877af46220e3c79771cb6498946bc0
parent40ceee969bd29508c1da28052c95eb85a52650ba (diff)
downloadaerc-00263bf8668130abb4aa5ac3383aeb9865e71328.tar.gz
modify-labels: add completion
-rw-r--r--commands/commands.go35
-rw-r--r--commands/msg/modify-labels.go3
2 files changed, 37 insertions, 1 deletions
diff --git a/commands/commands.go b/commands/commands.go
index 1e86118..39720bf 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -2,6 +2,7 @@ package commands
 
 import (
 	"errors"
+	"fmt"
 	"sort"
 	"strings"
 	"unicode"
@@ -127,6 +128,40 @@ func GetFolders(aerc *widgets.Aerc, args []string) []string {
 	return out
 }
 
+func GetLabels(aerc *widgets.Aerc, args []string) []string {
+	if len(args) == 0 {
+		return aerc.SelectedAccount().Labels()
+	}
+
+	// + and - are used to denote tag addition / removal and need to be striped
+	// only the last tag should be completed, so that multiple labels can be
+	// selected
+	last := args[len(args)-1]
+	others := strings.Join(args[:len(args)-1], " ")
+	var prefix string
+	switch last[0] {
+	case '+':
+		prefix = "+"
+	case '-':
+		prefix = "-"
+	default:
+		prefix = ""
+	}
+	trimmed := strings.TrimLeft(last, "+-")
+
+	out := make([]string, 0)
+	for _, label := range aerc.SelectedAccount().Labels() {
+		if hasCaseSmartPrefix(label, trimmed) {
+			var prev string
+			if len(others) > 0 {
+				prev = others + " "
+			}
+			out = append(out, fmt.Sprintf("%v%v%v", prev, prefix, label))
+		}
+	}
+	return out
+}
+
 // hasCaseSmartPrefix checks whether s starts with prefix, using a case
 // sensitive match if and only if prefix contains upper case letters.
 func hasCaseSmartPrefix(s, prefix string) bool {
diff --git a/commands/msg/modify-labels.go b/commands/msg/modify-labels.go
index a18fc15..a53292e 100644
--- a/commands/msg/modify-labels.go
+++ b/commands/msg/modify-labels.go
@@ -4,6 +4,7 @@ import (
 	"errors"
 	"time"
 
+	"git.sr.ht/~sircmpwn/aerc/commands"
 	"git.sr.ht/~sircmpwn/aerc/widgets"
 	"git.sr.ht/~sircmpwn/aerc/worker/types"
 	"github.com/gdamore/tcell"
@@ -20,7 +21,7 @@ func (ModifyLabels) Aliases() []string {
 }
 
 func (ModifyLabels) Complete(aerc *widgets.Aerc, args []string) []string {
-	return nil
+	return commands.GetLabels(aerc, args)
 }
 
 func (ModifyLabels) Execute(aerc *widgets.Aerc, args []string) error {
3:12 +0100 committer hut <hut@lavabit.com> 2009-12-05 16:53:12 +0100 History Object + Test Case' href='/akspecs/ranger/commit/test/tc_history.py?h=v1.9.3&id=22bb7e358ccd6efc58c38b8703b6818131905a75'>22bb7e35 ^
3dbefa71 ^
22bb7e35 ^


3dbefa71 ^
22bb7e35 ^








1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44