aerc

Working clone of aerc-mail.org
git clone git://git.danielmoch.com/aerc.git
Log | Files | Refs | README | LICENSE

commit 513e8aa94b5a95698453250bc514b333b1768a6c
parent 9e3b602ce7317c18a73d228fda7eb476b18a8988
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 15 Mar 2019 10:47:09 -0400

Rename :cd -> :cf, add :cd

Diffstat:
Mcommands/cd.go | 32+++++++++++++++++++++-----------
Acommands/cf.go | 35+++++++++++++++++++++++++++++++++++
Mconfig/aerc.conf | 2+-
Mgo.mod | 1+
Mgo.sum | 2++
5 files changed, 60 insertions(+), 12 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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=