aboutsummaryrefslogtreecommitdiffstats
path: root/commands/compose/switch.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/compose/switch.go')
-rw-r--r--commands/compose/switch.go38
1 files changed, 33 insertions, 5 deletions
diff --git a/commands/compose/switch.go b/commands/compose/switch.go
index 5109ee05..58702b5b 100644
--- a/commands/compose/switch.go
+++ b/commands/compose/switch.go
@@ -5,6 +5,7 @@ import (
"fmt"
"git.sr.ht/~rjarry/aerc/widgets"
+ "git.sr.ht/~sircmpwn/getopt"
)
type AccountSwitcher interface {
@@ -26,12 +27,29 @@ func (SwitchAccount) Complete(aerc *widgets.Aerc, args []string) []string {
}
func (SwitchAccount) Execute(aerc *widgets.Aerc, args []string) error {
- if len(args) != 2 {
+ opts, optind, err := getopt.Getopts(args, "np")
+ if err != nil {
+ return err
+ }
+ var next, prev bool
+ for _, opt := range opts {
+ switch opt.Option {
+ case 'n':
+ next = true
+ prev = false
+ case 'p':
+ next = false
+ prev = true
+ }
+ }
+ posargs := args[optind:]
+ // NOT ((prev || next) XOR (len(posargs) == 1))
+ if (prev || next) == (len(posargs) == 1) {
name := ""
if acct := aerc.SelectedAccount(); acct != nil {
name = fmt.Sprintf("Current account: %s. ", acct.Name())
}
- return errors.New(name + "Usage: switch-account <account-name>")
+ return errors.New(name + "Usage: switch-account [-np] <account-name>")
}
switcher, ok := aerc.SelectedTabContent().(AccountSwitcher)
@@ -39,9 +57,19 @@ func (SwitchAccount) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("this tab cannot switch accounts")
}
- if acct, err := aerc.Account(args[1]); err != nil {
+ var acct *widgets.AccountView
+
+ switch {
+ case prev:
+ acct, err = aerc.PrevAccount()
+ case next:
+ acct, err = aerc.NextAccount()
+ default:
+ acct, err = aerc.Account(posargs[0])
+ }
+ if err != nil {
return err
- } else {
- return switcher.SwitchAccount(acct)
}
+
+ return switcher.SwitchAccount(acct)
}