summary refs log tree commit diff stats
path: root/commands/cf.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-15 10:47:09 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-15 10:47:09 -0400
commit513e8aa94b5a95698453250bc514b333b1768a6c (patch)
tree6c988566c3d247a189a537d85b47245b8b6d57bb /commands/cf.go
parent9e3b602ce7317c18a73d228fda7eb476b18a8988 (diff)
downloadaerc-513e8aa94b5a95698453250bc514b333b1768a6c.tar.gz
Rename :cd -> :cf, add :cd
Diffstat (limited to 'commands/cf.go')
-rw-r--r--commands/cf.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/commands/cf.go b/commands/cf.go
new file mode 100644
index 0000000..83b757c
--- /dev/null
+++ b/commands/cf.go
@@ -0,0 +1,35 @@
+package commands
+
+import (
+	"errors"
+
+	"git.sr.ht/~sircmpwn/aerc2/widgets"
+)
+
+var (
+	history map[string]string
+)
+
+func init() {
+	history = make(map[string]string)
+	Register("cf", ChangeFolder)
+}
+
+func ChangeFolder(aerc *widgets.Aerc, args []string) error {
+	if len(args) != 2 {
+		return errors.New("Usage: cf <folder>")
+	}
+	acct := aerc.SelectedAccount()
+	previous := acct.Directories().Selected()
+	if args[1] == "-" {
+		if dir, ok := history[acct.Name()]; ok {
+			acct.Directories().Select(dir)
+		} else {
+			return errors.New("No previous folder to return to")
+		}
+	} else {
+		acct.Directories().Select(args[1])
+	}
+	history[acct.Name()] = previous
+	return nil
+}