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 /config/openers.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 'config/openers.go')
-rw-r--r-- | config/openers.go | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/config/openers.go b/config/openers.go index 181536f5..e246ea64 100644 --- a/config/openers.go +++ b/config/openers.go @@ -1,6 +1,7 @@ package config import ( + "fmt" "strings" "git.sr.ht/~rjarry/aerc/log" @@ -8,7 +9,12 @@ import ( "github.com/google/shlex" ) -var Openers = make(map[string][]string) +type Opener struct { + Mime string + Args []string +} + +var Openers []Opener func parseOpeners(file *ini.File) error { openers, err := file.GetSection("openers") @@ -16,12 +22,15 @@ func parseOpeners(file *ini.File) error { goto out } - for mimeType, command := range openers.KeysHash() { - mimeType = strings.ToLower(mimeType) - if args, err := shlex.Split(command); err != nil { + for _, key := range openers.Keys() { + mime := strings.ToLower(key.Name()) + if args, err := shlex.Split(key.Value()); err != nil { return err } else { - Openers[mimeType] = args + if len(args) == 0 { + return fmt.Errorf("opener command empty for %s", mime) + } + Openers = append(Openers, Opener{Mime: mime, Args: args}) } } |