diff options
author | Robin Jarry <robin@jarry.cc> | 2023-09-24 21:10:19 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-10-28 19:25:02 +0200 |
commit | 1db74a9ba74350776dee5f2384744357ad3aace5 (patch) | |
tree | 923e7ef487ee71876620d4f8370b06a543f5fb79 /lib/open.go | |
parent | 8464b373851142b0becaaa10db34df3559b2b62e (diff) | |
download | aerc-1db74a9ba74350776dee5f2384744357ad3aace5.tar.gz |
open: run commands with sh -c
Allow running shell commands in openers.
Changelog-changed: `:open` commands are now executed with `sh -c`.
Requested-by: Vitaly Ovchinnikov <v@postbox.nz>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'lib/open.go')
-rw-r--r-- | lib/open.go | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/open.go b/lib/open.go index b60c4165..21bee748 100644 --- a/lib/open.go +++ b/lib/open.go @@ -6,19 +6,21 @@ import ( "runtime" "strings" + "git.sr.ht/~rjarry/go-opt" + "github.com/danwakefield/fnmatch" + "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/log" - "github.com/danwakefield/fnmatch" ) func XDGOpenMime( - uri string, mimeType string, args []string, + uri string, mimeType string, args string, ) error { if len(args) == 0 { // no explicit command provided, lookup opener from mime type for _, o := range config.Openers { if fnmatch.Match(o.Mime, mimeType, 0) { - args = append(args, o.Args...) + args = o.Args break } } @@ -26,28 +28,24 @@ func XDGOpenMime( if len(args) == 0 { // no opener defined in config, fallback to default if runtime.GOOS == "darwin" { - args = append(args, "open") + args = "open" } else { - args = append(args, "xdg-open") + args = "xdg-open" } } - i := 0 - for ; i < len(args); i++ { - if strings.Contains(args[i], "{}") { - break - } - } - if i < len(args) { + // Escape URI special characters + uri = opt.QuoteArg(uri) + if strings.Contains(args, "{}") { // found {} placeholder in args, replace with uri - args[i] = strings.Replace(args[i], "{}", uri, 1) + args = strings.Replace(args, "{}", uri, 1) } else { // no {} placeholder in args, add uri at the end - args = append(args, uri) + args = args + " " + uri } log.Tracef("running command: %v", args) - cmd := exec.Command(args[0], args[1:]...) + cmd := exec.Command("sh", "-c", args) out, err := cmd.CombinedOutput() log.Debugf("command: %v exited. err=%v out=%s", args, err, out) if err != nil { |