summary refs log tree commit diff stats
path: root/commands/cd.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/cd.go
parent9e3b602ce7317c18a73d228fda7eb476b18a8988 (diff)
downloadaerc-513e8aa94b5a95698453250bc514b333b1768a6c.tar.gz
Rename :cd -> :cf, add :cd
Diffstat (limited to 'commands/cd.go')
-rw-r--r--commands/cd.go32
1 files changed, 21 insertions, 11 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
 }
a id='n171' href='#n171'>171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275