aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/aerc.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-10-28 12:20:20 -0500
committerRobin Jarry <robin@jarry.cc>2022-11-06 23:17:40 +0100
commitb9153795a9cdee36441ec47d9e35274ba4b37f37 (patch)
treedff0e69303e8bd00034d54306cd09aa07076f705 /widgets/aerc.go
parent62deed1379338ef8fc8133b9606e8f0e534a257e (diff)
downloadaerc-b9153795a9cdee36441ec47d9e35274ba4b37f37.tar.gz
compose: warn user when editor is not in PATH
Warn user when configured editor is not in path. Attempt fallbacks, and throw error if none of the fallbacks are in PATH. Fixes: https://todo.sr.ht/~rjarry/aerc/94 Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets/aerc.go')
-rw-r--r--widgets/aerc.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go
index aef874b3..75b7d5ae 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/url"
+ "os/exec"
"sort"
"strings"
"time"
@@ -863,3 +864,24 @@ func (aerc *Aerc) isExKey(event *tcell.EventKey, exKey config.KeyStroke) bool {
}
return event.Modifiers() == exKey.Modifiers && event.Key() == exKey.Key
}
+
+// CmdFallbackSearch checks cmds for the first executable availabe in PATH. An error is
+// returned if none are found
+func (aerc *Aerc) CmdFallbackSearch(cmds []string) (string, error) {
+ var tried []string
+ for _, cmd := range cmds {
+ if cmd == "" {
+ continue
+ }
+ params := strings.Split(cmd, " ")
+ _, err := exec.LookPath(params[0])
+ if err != nil {
+ tried = append(tried, cmd)
+ warn := fmt.Sprintf("cmd '%s' not found in PATH, using fallback", cmd)
+ aerc.PushWarning(warn)
+ continue
+ }
+ return cmd, nil
+ }
+ return "", fmt.Errorf("no command found in PATH: %s", tried)
+}