mirror of
https://git.sr.ht/~rjarry/aerc
synced 2026-03-02 18:23:33 +01:00
hooks: add aerc-startup hook
Add a hook to run when aerc starts up. The environment is supplemented with aerc version and the path to its binary. References: https://todo.sr.ht/~rjarry/aerc/136 References: https://todo.sr.ht/~rjarry/aerc/139 Signed-off-by: Moritz Poldrack <git@moritz.sh> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
This commit is contained in:
committed by
Robin Jarry
parent
2fef0f4a60
commit
f10b184eb3
@@ -22,7 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
`aerc.conf`.
|
||||
- Allow basic shell globbing in `[openers]` MIME types.
|
||||
- Dynamic `msglist_*` styling based on email header values in stylesets.
|
||||
- Add `mail-received` hook.
|
||||
- Add `mail-received` and `aerc-startup` hooks.
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@@ -514,6 +514,10 @@ message/rfc822=colorize
|
||||
# Executed when a new email arrives in the selected folder
|
||||
#mail-received=notify-send "New mail from $AERC_FROM_NAME" "$AERC_SUBJECT"
|
||||
|
||||
#
|
||||
# Executed when aerc starts
|
||||
#aerc-startup=aerc :terminal calcurse && aerc :next-tab
|
||||
|
||||
[templates]
|
||||
# Templates are used to populate email bodies automatically.
|
||||
#
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type HooksConfig struct {
|
||||
AercStartup string `ini:"aerc-startup"`
|
||||
MailReceived string `ini:"mail-received"`
|
||||
}
|
||||
|
||||
|
||||
@@ -826,6 +826,21 @@ in a shell environment with information added to environment variables.
|
||||
|
||||
They are configured in the *[hooks]* section of aerc.conf.
|
||||
|
||||
*aerc-startup* = _<command>_
|
||||
Executed when aerc is started is received in the selected folder. If it
|
||||
is used to run certain commands at startup. The hook is executed as soon
|
||||
as the UI is initialized and does not wait for all accounts to be fully
|
||||
loaded.
|
||||
|
||||
Variables:
|
||||
|
||||
- *AERC_VERSION*
|
||||
- *AERC_BINARY*
|
||||
|
||||
Example:
|
||||
|
||||
*aerc-startup* = _aerc :terminal calcurse && aerc :next-tab_
|
||||
|
||||
*mail-received* = _<command>_
|
||||
Executed when new mail is received in the selected folder. This will
|
||||
only work reliably with maildir and some imap servers.
|
||||
|
||||
23
lib/hooks/aerc-startup.go
Normal file
23
lib/hooks/aerc-startup.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package hooks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.sr.ht/~rjarry/aerc/config"
|
||||
)
|
||||
|
||||
type AercStartup struct {
|
||||
Version string
|
||||
}
|
||||
|
||||
func (m *AercStartup) Cmd() string {
|
||||
return config.Hooks.AercStartup
|
||||
}
|
||||
|
||||
func (m *AercStartup) Env() []string {
|
||||
return []string{
|
||||
fmt.Sprintf("AERC_VERSION=%s", m.Version),
|
||||
fmt.Sprintf("AERC_BINARY=%s", os.Args[0]),
|
||||
}
|
||||
}
|
||||
9
main.go
9
main.go
@@ -23,6 +23,7 @@ import (
|
||||
"git.sr.ht/~rjarry/aerc/commands/terminal"
|
||||
"git.sr.ht/~rjarry/aerc/config"
|
||||
"git.sr.ht/~rjarry/aerc/lib/crypto"
|
||||
"git.sr.ht/~rjarry/aerc/lib/hooks"
|
||||
"git.sr.ht/~rjarry/aerc/lib/ipc"
|
||||
"git.sr.ht/~rjarry/aerc/lib/templates"
|
||||
libui "git.sr.ht/~rjarry/aerc/lib/ui"
|
||||
@@ -242,6 +243,14 @@ func main() {
|
||||
}
|
||||
|
||||
ui.ChannelEvents()
|
||||
go func() {
|
||||
defer log.PanicHandler()
|
||||
err := hooks.RunHook(&hooks.AercStartup{Version: Version})
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("aerc-startup hook: %s", err)
|
||||
aerc.PushError(msg)
|
||||
}
|
||||
}()
|
||||
for event := range libui.MsgChannel {
|
||||
switch event := event.(type) {
|
||||
case tcell.Event:
|
||||
|
||||
Reference in New Issue
Block a user