aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-08-15 21:58:43 +0200
committerRobin Jarry <robin@jarry.cc>2022-09-19 21:26:34 +0200
commitd371c1ac8d03146512311c73b43ae90813ded9b0 (patch)
treebc6dbd5025e7112b11fc8a8ba3db42568d14af9b /commands
parentee4f2ea49d82a27328f3a154e9f91dc91d69e990 (diff)
downloadaerc-d371c1ac8d03146512311c73b43ae90813ded9b0.tar.gz
commands: add switch-account command for composer
Switch accounts when in the composer mode. When switching accounts, the From header, the crypto status and the address completer will be updated. Accounts can be switched with :switch-account <account-name>. The completions for the switch-account command will list the available accounts. If switch-account is run without arguments, the current account name with the correct usage is displayed. Fixes: https://todo.sr.ht/~rjarry/aerc/72 Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r--commands/compose/switch.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/commands/compose/switch.go b/commands/compose/switch.go
new file mode 100644
index 00000000..5109ee05
--- /dev/null
+++ b/commands/compose/switch.go
@@ -0,0 +1,47 @@
+package compose
+
+import (
+ "errors"
+ "fmt"
+
+ "git.sr.ht/~rjarry/aerc/widgets"
+)
+
+type AccountSwitcher interface {
+ SwitchAccount(*widgets.AccountView) error
+}
+
+type SwitchAccount struct{}
+
+func init() {
+ register(SwitchAccount{})
+}
+
+func (SwitchAccount) Aliases() []string {
+ return []string{"switch-account"}
+}
+
+func (SwitchAccount) Complete(aerc *widgets.Aerc, args []string) []string {
+ return aerc.AccountNames()
+}
+
+func (SwitchAccount) Execute(aerc *widgets.Aerc, args []string) error {
+ if len(args) != 2 {
+ name := ""
+ if acct := aerc.SelectedAccount(); acct != nil {
+ name = fmt.Sprintf("Current account: %s. ", acct.Name())
+ }
+ return errors.New(name + "Usage: switch-account <account-name>")
+ }
+
+ switcher, ok := aerc.SelectedTabContent().(AccountSwitcher)
+ if !ok {
+ return errors.New("this tab cannot switch accounts")
+ }
+
+ if acct, err := aerc.Account(args[1]); err != nil {
+ return err
+ } else {
+ return switcher.SwitchAccount(acct)
+ }
+}