diff options
author | Robin Jarry <robin@jarry.cc> | 2023-03-12 11:33:06 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-03-13 23:35:52 +0100 |
commit | c15c91e609c242feeaeb23984cec8a9f64607061 (patch) | |
tree | 53c0d4800e639bae828b692873abd2e871f64c2e /lib/open.go | |
parent | 49f58adda429c54225d79d13bfad7a054ae29db2 (diff) | |
download | aerc-c15c91e609c242feeaeb23984cec8a9f64607061.tar.gz |
openers: support basic shell globbing
Allow wild cards for MIME types like in filters.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Diffstat (limited to 'lib/open.go')
-rw-r--r-- | lib/open.go | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/open.go b/lib/open.go index 0af51d1c..b60c4165 100644 --- a/lib/open.go +++ b/lib/open.go @@ -8,6 +8,7 @@ import ( "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/log" + "github.com/danwakefield/fnmatch" ) func XDGOpenMime( @@ -15,18 +16,21 @@ func XDGOpenMime( ) error { if len(args) == 0 { // no explicit command provided, lookup opener from mime type - opener, ok := config.Openers[mimeType] - if ok { - args = opener - } else { - // no opener defined in config, fallback to default - if runtime.GOOS == "darwin" { - args = append(args, "open") - } else { - args = append(args, "xdg-open") + for _, o := range config.Openers { + if fnmatch.Match(o.Mime, mimeType, 0) { + args = append(args, o.Args...) + break } } } + if len(args) == 0 { + // no opener defined in config, fallback to default + if runtime.GOOS == "darwin" { + args = append(args, "open") + } else { + args = append(args, "xdg-open") + } + } i := 0 for ; i < len(args); i++ { |