aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hooks/exec.go
blob: bea35f32c0e861f27fc113eadbc6dd165837df30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package hooks

import (
	"os"
	"os/exec"

	"git.sr.ht/~rjarry/aerc/log"
)

func RunHook(h HookType) error {
	cmd := h.Cmd()
	if cmd == "" {
		return nil
	}
	env := h.Env()
	log.Debugf("hooks: running command %q (env %v)", cmd, env)

	proc := exec.Command("sh", "-c", cmd)
	proc.Env = os.Environ()
	proc.Env = append(proc.Env, env...)
	return proc.Run()
}