From d371c1ac8d03146512311c73b43ae90813ded9b0 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Mon, 15 Aug 2022 21:58:43 +0200 Subject: [PATCH] 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 . 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 Acked-by: Robin Jarry --- commands/compose/switch.go | 47 ++++++++++++++++++++++++++++++++++++++ doc/aerc.1.scd | 4 ++++ 2 files changed, 51 insertions(+) create mode 100644 commands/compose/switch.go diff --git a/commands/compose/switch.go b/commands/compose/switch.go new file mode 100644 index 0000000..5109ee0 --- /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 ") + } + + 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) + } +} diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd index 40b14d8..f0ca97e 100644 --- a/doc/aerc.1.scd +++ b/doc/aerc.1.scd @@ -476,6 +476,10 @@ message list, the message in the message viewer, etc). configuration. For details on configuring outgoing mail delivery consult *aerc-config*(5). +*switch-account* + Switches the account. If run without arguments, the current account name + is displayed. + *header* [-f] [value] Add a new email header. If the header already exists, -f must be specified to replace the given value.