about summary refs log tree commit diff stats
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
parent9e3b602ce7317c18a73d228fda7eb476b18a8988 (diff)
downloadaerc-513e8aa94b5a95698453250bc514b333b1768a6c.tar.gz
Rename :cd -> :cf, add :cd
-rw-r--r--commands/cd.go32
-rw-r--r--commands/cf.go35
-rw-r--r--config/aerc.conf2
-rw-r--r--go.mod1
-rw-r--r--go.sum2
5 files changed, 60 insertions, 12 deletions
diff --git a/commands/cd.go b/commands/cd.go
index e3a1953..52d5b49 100644
--- a/commands/cd.go
+++ b/commands/cd.go
@@ -2,34 +2,44 @@ package commands
 
 import (
 	"errors"
+	"os"
 
 	"git.sr.ht/~sircmpwn/aerc2/widgets"
+	"github.com/mitchellh/go-homedir"
 )
 
 var (
-	history map[string]string
+	previousDir string
 )
 
 func init() {
-	history = make(map[string]string)
 	Register("cd", ChangeDirectory)
 }
 
 func ChangeDirectory(aerc *widgets.Aerc, args []string) error {
 	if len(args) != 2 {
-		return errors.New("Usage: cd <directory>")
+		return errors.New("Usage: cf <directory>")
 	}
-	acct := aerc.SelectedAccount()
-	previous := acct.Directories().Selected()
+	cwd, err := os.Getwd()
+	if err != nil {
+		return err
+	}
+	var target string
 	if args[1] == "-" {
-		if dir, ok := history[acct.Name()]; ok {
-			acct.Directories().Select(dir)
+		if previousDir == "" {
+			return errors.New("No previous folder to return to")
 		} else {
-			return errors.New("No previous directory to return to")
+			target = previousDir
 		}
 	} else {
-		acct.Directories().Select(args[1])
+		target = args[1]
+	}
+	target, err = homedir.Expand(target)
+	if err != nil {
+		return err
+	}
+	if err := os.Chdir(target); err == nil {
+		previousDir = cwd
 	}
-	history[acct.Name()] = previous
-	return nil
+	return err
 }
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
+}
diff --git a/config/aerc.conf b/config/aerc.conf
index f9c91b8..30953fc 100644
--- a/config/aerc.conf
+++ b/config/aerc.conf
@@ -125,7 +125,7 @@ h = :prev-account<Enter>
 <Enter> = :view-message<Enter>
 d = :confirm 'Really delete this message?' ':delete-message<Enter>'<Enter>
 
-c = :cd<space>
+c = :cf<space>
 $ = :term-exec 
 
 [mbinds]
diff --git a/go.mod b/go.mod
index 5eae665..13a1259 100644
--- a/go.mod
+++ b/go.mod
@@ -12,6 +12,7 @@ require (
 	github.com/lucasb-eyer/go-colorful v0.0.0-20180531031333-d9cec903b20c
 	github.com/mattn/go-isatty v0.0.3
 	github.com/mattn/go-runewidth v0.0.2
+	github.com/mitchellh/go-homedir v1.1.0
 	github.com/nsf/termbox-go v0.0.0-20180129072728-88b7b944be8b
 	github.com/stretchr/testify v1.3.0
 	golang.org/x/text v0.3.0
diff --git a/go.sum b/go.sum
index 1278e7a..99e88d9 100644
--- a/go.sum
+++ b/go.sum
@@ -24,6 +24,8 @@ github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI
 github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
 github.com/mattn/go-runewidth v0.0.2 h1:UnlwIPBGaTZfPQ6T1IGzPI0EkYAQmT9fAEJ/poFC63o=
 github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
+github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
+github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
 github.com/nsf/termbox-go v0.0.0-20180129072728-88b7b944be8b/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=