diff options
author | Robin Jarry <robin@jarry.cc> | 2023-02-01 23:35:42 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-02-20 14:48:42 +0100 |
commit | aaaa0c184fb43879cc84551983309cad06d665ee (patch) | |
tree | 93bb83d32495f679a70dbe5d3913549c29edf675 /commands | |
parent | 420a82a356d53e4b600ba54768f7ed21a43cf85e (diff) | |
download | aerc-aaaa0c184fb43879cc84551983309cad06d665ee.tar.gz |
triggers: use templates instead of % mini language
Since previous commit, all commands now support expanding text/template
markup. Reuse that for the new-email trigger command.
Update commands.ExecuteCommand to take optional *AccountConfig and
*MessageInfo arguments. If these are nil, fallback to using the
currently selected account and message (if any).
Pass the proper *AccountConfig and *MessageInfo objects when firing the
trigger command so that these are used instead of the currently selected
ones.
If new-email contains % placeholders, try to convert them to template
markup reusing the same conversion added in commit 535300cfdbfc
("config: add columns based index format"). Warn the user that they need
to update their configuration file.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/commands.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/commands/commands.go b/commands/commands.go index bbd03237..cf96a39e 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -70,15 +70,21 @@ type CommandSource interface { Commands() *Commands } -func templateData(aerc *widgets.Aerc) models.TemplateData { +func templateData( + aerc *widgets.Aerc, + cfg *config.AccountConfig, + msg *models.MessageInfo, +) models.TemplateData { var folder string - var cfg *config.AccountConfig - var msg *models.MessageInfo acct := aerc.SelectedAccount() if acct != nil { folder = acct.SelectedDirectory() + } + if cfg == nil && acct != nil { cfg = acct.AccountConfig() + } + if msg == nil && acct != nil { msg, _ = acct.SelectedMessage() } @@ -91,14 +97,19 @@ func templateData(aerc *widgets.Aerc) models.TemplateData { return &data } -func (cmds *Commands) ExecuteCommand(aerc *widgets.Aerc, args []string) error { +func (cmds *Commands) ExecuteCommand( + aerc *widgets.Aerc, + args []string, + account *config.AccountConfig, + msg *models.MessageInfo, +) error { if len(args) == 0 { return errors.New("Expected a command.") } if cmd, ok := cmds.dict()[args[0]]; ok { log.Tracef("executing command %v", args) var buf bytes.Buffer - data := templateData(aerc) + data := templateData(aerc, account, msg) processedArgs := make([]string, len(args)) for i, arg := range args { |