diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-10-28 12:20:20 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-11-06 23:17:40 +0100 |
commit | b9153795a9cdee36441ec47d9e35274ba4b37f37 (patch) | |
tree | dff0e69303e8bd00034d54306cd09aa07076f705 /widgets/aerc.go | |
parent | 62deed1379338ef8fc8133b9606e8f0e534a257e (diff) | |
download | aerc-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.go | 22 |
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) +} |