aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2023-03-15 22:40:38 +0100
committerRobin Jarry <robin@jarry.cc>2023-04-01 01:01:09 +0200
commitf10b184eb34634b9642fa83ef0f1cd8d0687a4af (patch)
tree8806be0073294a1d6542fa0447d8fee8e12230e5
parent2fef0f4a60c8026c156ad8d75078bccde6a540d8 (diff)
downloadaerc-f10b184eb34634b9642fa83ef0f1cd8d0687a4af.tar.gz
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>
-rw-r--r--CHANGELOG.md2
-rw-r--r--config/aerc.conf4
-rw-r--r--config/hooks.go1
-rw-r--r--doc/aerc-config.5.scd15
-rw-r--r--lib/hooks/aerc-startup.go23
-rw-r--r--main.go9
6 files changed, 53 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4d5b15b2..4ee452df 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/config/aerc.conf b/config/aerc.conf
index 5ff252f5..110e8459 100644
--- a/config/aerc.conf
+++ b/config/aerc.conf
@@ -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.
#
diff --git a/config/hooks.go b/config/hooks.go
index 9bbd9031..41fc8026 100644
--- a/config/hooks.go
+++ b/config/hooks.go
@@ -8,6 +8,7 @@ import (
)
type HooksConfig struct {
+ AercStartup string `ini:"aerc-startup"`
MailReceived string `ini:"mail-received"`
}
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 9e11abfe..78267229 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -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.
diff --git a/lib/hooks/aerc-startup.go b/lib/hooks/aerc-startup.go
new file mode 100644
index 00000000..a53d070e
--- /dev/null
+++ b/lib/hooks/aerc-startup.go
@@ -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]),
+ }
+}
diff --git a/main.go b/main.go
index 49684c53..9b76d0cc 100644
--- a/main.go
+++ b/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: