aerc/commands/account/next-folder.go

54 lines
951 B
Go
Raw Normal View History

2019-03-21 21:30:23 +01:00
package account
2019-03-11 02:15:24 +01:00
import (
2019-03-11 02:23:22 +01:00
"errors"
"fmt"
"strconv"
2019-05-18 02:57:10 +02:00
"git.sr.ht/~sircmpwn/aerc/widgets"
2019-03-11 02:15:24 +01:00
)
type NextPrevFolder struct{}
2019-03-11 02:15:24 +01:00
func init() {
register(NextPrevFolder{})
2019-03-11 02:23:22 +01:00
}
func (NextPrevFolder) Aliases() []string {
return []string{"next-folder", "prev-folder"}
}
func (NextPrevFolder) Complete(aerc *widgets.Aerc, args []string) []string {
return nil
2019-03-11 02:15:24 +01:00
}
func (NextPrevFolder) Execute(aerc *widgets.Aerc, args []string) error {
2019-03-11 02:23:22 +01:00
if len(args) > 2 {
2019-03-15 04:41:25 +01:00
return nextPrevFolderUsage(args[0])
2019-03-11 02:23:22 +01:00
}
var (
n int = 1
err error
)
if len(args) > 1 {
n, err = strconv.Atoi(args[1])
if err != nil {
2019-03-15 04:41:25 +01:00
return nextPrevFolderUsage(args[0])
2019-03-11 02:23:22 +01:00
}
}
2019-03-11 02:15:24 +01:00
acct := aerc.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
if args[0] == "prev-folder" {
acct.Directories().NextPrev(-n)
} else {
acct.Directories().NextPrev(n)
2019-03-11 02:23:22 +01:00
}
2019-03-11 02:15:24 +01:00
return nil
}
func nextPrevFolderUsage(cmd string) error {
return fmt.Errorf("Usage: %s [n]", cmd)
}