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 | |
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')
-rw-r--r-- | config/aerc.conf | 6 | ||||
-rw-r--r-- | config/openers.go | 19 |
2 files changed, 19 insertions, 6 deletions
diff --git a/config/aerc.conf b/config/aerc.conf index bd8b08d8..02ea96fe 100644 --- a/config/aerc.conf +++ b/config/aerc.conf @@ -495,9 +495,13 @@ message/rfc822=colorize # encountered in the command, the temporary filename will be appened to the end # of the command. # +# Like [filters], openers support basic shell globbing. The first opener which +# matches the part's MIME type (or URL scheme handler MIME type) will be used, +# so order them from most to least specific. +# # Examples: # x-scheme-handler/irc=hexchat -# x-scheme-handler/http=firefox +# x-scheme-handler/http*=firefox # text/html=surf -dfgms # text/plain=gvim {} +125 # message/rfc822=thunderbird 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}) } } |