filters: export mime type and filename in env

Export AERC_MIME_TYPE and AERC_FILENAME in the filters command
environment. This allows dynamic coloring with tools that require
a filename and/or a mime type to determine the syntax.

Update docs and add example use in the default config file.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
This commit is contained in:
Robin Jarry 2022-10-13 00:03:42 +02:00
parent 9bd2e0c84f
commit ebfd2a9da3
4 changed files with 21 additions and 1 deletions

View file

@ -541,8 +541,9 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig,
pager = exec.Command(cmd[0], cmd[1:]...)
info := msg.MessageInfo()
mime := part.FullMIMEType()
for _, f := range conf.Filters {
mime := part.FullMIMEType()
switch f.FilterType {
case config.FILTER_MIMETYPE:
if fnmatch.Match(f.Filter, mime, 0) {
@ -577,6 +578,10 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig,
}
filter.Env = os.Environ()
filter.Env = append(filter.Env, fmt.Sprintf("PATH=%s", path))
filter.Env = append(filter.Env,
fmt.Sprintf("AERC_MIME_TYPE=%s", mime))
filter.Env = append(filter.Env,
fmt.Sprintf("AERC_FILENAME=%s", part.FileName()))
if pipe, err = filter.StdinPipe(); err != nil {
return nil, err
}