From ebfd2a9da3d63390a9d4a0c227b2513a0dac19a4 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Thu, 13 Oct 2022 00:03:42 +0200 Subject: 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 Acked-by: Moritz Poldrack --- widgets/msgviewer.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'widgets/msgviewer.go') diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index 70c079a3..a32e0399 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -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 } -- cgit