about summary refs log tree commit diff stats
path: root/commands
diff options
context:
space:
mode:
authorGregory Mullen <greg@cmdline.org>2019-07-03 09:54:10 -0700
committerDrew DeVault <sir@cmpwn.com>2019-07-04 11:28:04 -0400
commitf9d26eef58ce2b9fa1e2443032c17c2ccc6afa36 (patch)
tree86ca1765c913f9c3285755a1ea3874110dd8da04 /commands
parent8d9d94f0ee63216b50674d0857ef1f2c744737d5 (diff)
downloadaerc-f9d26eef58ce2b9fa1e2443032c17c2ccc6afa36.tar.gz
Add IMAP folder tab completion
Credit for this fix goes to Reto; I guess if we're not gonna be mutt
we should probabaly do things correctly.
Diffstat (limited to 'commands')
-rw-r--r--commands/account/cf.go3
-rw-r--r--commands/commands.go23
-rw-r--r--commands/msg/move.go3
3 files changed, 27 insertions, 2 deletions
diff --git a/commands/account/cf.go b/commands/account/cf.go
index 197e956..6c928ea 100644
--- a/commands/account/cf.go
+++ b/commands/account/cf.go
@@ -3,6 +3,7 @@ package account
 import (
 	"errors"
 
+	"git.sr.ht/~sircmpwn/aerc/commands"
 	"git.sr.ht/~sircmpwn/aerc/widgets"
 )
 
@@ -22,7 +23,7 @@ func (_ ChangeFolder) Aliases() []string {
 }
 
 func (_ ChangeFolder) Complete(aerc *widgets.Aerc, args []string) []string {
-	return nil
+	return commands.GetFolders(aerc, args)
 }
 
 func (_ ChangeFolder) Execute(aerc *widgets.Aerc, args []string) error {
diff --git a/commands/commands.go b/commands/commands.go
index 8d50b41..e53bdfe 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -3,6 +3,7 @@ package commands
 import (
 	"errors"
 	"strings"
+	"unicode"
 
 	"github.com/google/shlex"
 
@@ -108,3 +109,25 @@ func (cmds *Commands) GetCompletions(aerc *widgets.Aerc, cmd string) []string {
 	}
 	return nil
 }
+
+const caps string = "ABCDEFGHIJKLMNOPQRSTUVXYZ"
+
+func GetFolders(aerc *widgets.Aerc, args []string) []string {
+	out := make([]string, 0)
+	lower_only := false
+	for _, rune := range args[0] {
+		lower_only = lower_only || unicode.IsLower(rune)
+	}
+
+	for _, dir := range aerc.SelectedAccount().Directories().List() {
+		test := dir
+		if lower_only {
+			test = strings.ToLower(dir)
+		}
+
+		if strings.HasPrefix(test, args[0]) {
+			out = append(out, dir)
+		}
+	}
+	return out
+}
diff --git a/commands/msg/move.go b/commands/msg/move.go
index 45199b6..c98157e 100644
--- a/commands/msg/move.go
+++ b/commands/msg/move.go
@@ -7,6 +7,7 @@ import (
 	"git.sr.ht/~sircmpwn/getopt"
 	"github.com/gdamore/tcell"
 
+	"git.sr.ht/~sircmpwn/aerc/commands"
 	"git.sr.ht/~sircmpwn/aerc/widgets"
 	"git.sr.ht/~sircmpwn/aerc/worker/types"
 )
@@ -22,7 +23,7 @@ func (_ Move) Aliases() []string {
 }
 
 func (_ Move) Complete(aerc *widgets.Aerc, args []string) []string {
-	return nil
+	return commands.GetFolders(aerc, args)
 }
 
 func (_ Move) Execute(aerc *widgets.Aerc, args []string) error {