filters: append well known dirs to exec PATH
To allow referencing built-in filters without hard coding a path during installation, append the following folders to the exec PATH when running the filter commands: ~/.config/aerc/filters ~/.local/share/aerc/filters $PREFIX/share/aerc/filters /usr/share/aerc/filters If a filter script has the same name than a command in the default exec PATH, it will not shadow it. In that edge case, the absolute path to the filter script must be specified. Suggested-by: Teo Luppi <me@luppi.uk> Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
This commit is contained in:
parent
9cf69747eb
commit
c95961fc74
5 changed files with 31 additions and 3 deletions
|
@ -28,6 +28,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
history.
|
||||
- Embedded terminal backend (libvterm was replaced by a pure go implementation).
|
||||
- Use event driven loop instead of Tick based
|
||||
- Filter commands are now executed with
|
||||
`:~/.config/aerc/filters:~/.local/share/aerc/filters:$PREFIX/share/aerc/filters:/usr/share/aerc/filters`
|
||||
appended to the exec `PATH`. This allows referencing aerc's built-in filter
|
||||
scripts from their name only.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -302,6 +302,14 @@ reply-to-self=true
|
|||
# Filters allow you to pipe an email body through a shell command to render
|
||||
# certain emails differently, e.g. highlighting them with ANSI escape codes.
|
||||
#
|
||||
# The commands are invoked with sh -c. The following folders are appended to
|
||||
# the system $PATH to allow referencing filters from their name only:
|
||||
#
|
||||
# ${XDG_CONFIG_HOME:-~/.config}/aerc/filters
|
||||
# ${XDG_DATA_HOME:-~/.local/share}/aerc/filters
|
||||
# $PREFIX/share/aerc/filters
|
||||
# /usr/share/aerc/filters
|
||||
#
|
||||
# The first filter which matches the email's mimetype will be used, so order
|
||||
# them from most to least specific.
|
||||
#
|
||||
|
|
|
@ -426,7 +426,7 @@ func buildDefaultDirs() []string {
|
|||
return defaultDirs
|
||||
}
|
||||
|
||||
var searchDirs = buildDefaultDirs()
|
||||
var SearchDirs = buildDefaultDirs()
|
||||
|
||||
func installTemplate(root, name string) error {
|
||||
var err error
|
||||
|
@ -437,7 +437,7 @@ func installTemplate(root, name string) error {
|
|||
}
|
||||
}
|
||||
var data []byte
|
||||
for _, dir := range searchDirs {
|
||||
for _, dir := range SearchDirs {
|
||||
data, err = os.ReadFile(path.Join(dir, name))
|
||||
if err == nil {
|
||||
break
|
||||
|
@ -597,7 +597,7 @@ func (config *AercConfig) LoadConfig(file *ini.File) error {
|
|||
}
|
||||
|
||||
// append default paths to template-dirs and styleset-dirs
|
||||
for _, dir := range searchDirs {
|
||||
for _, dir := range SearchDirs {
|
||||
config.Ui.StyleSetDirs = append(
|
||||
config.Ui.StyleSetDirs, path.Join(dir, "stylesets"),
|
||||
)
|
||||
|
|
|
@ -510,6 +510,16 @@ aerc ships with some default filters installed in the share directory (usually
|
|||
_/usr/share/aerc/filters_). Note that these may have additional dependencies
|
||||
that aerc does not have alone.
|
||||
|
||||
The filter commands are invoked with sh -c [command]. The following folders are
|
||||
appended to the system $PATH to allow referencing filters from their name only.
|
||||
|
||||
```
|
||||
${XDG_CONFIG_HOME:-~/.config}/aerc/filters
|
||||
${XDG_DATA_HOME:-~/.local/share}/aerc/filters
|
||||
$PREFIX/share/aerc/filters
|
||||
/usr/share/aerc/filters
|
||||
```
|
||||
|
||||
Note that said email body is converted into UTF-8 before being passed to
|
||||
filters.
|
||||
|
||||
|
|
|
@ -577,6 +577,12 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig,
|
|||
}
|
||||
}
|
||||
if filter != nil {
|
||||
path, _ := os.LookupEnv("PATH")
|
||||
for _, dir := range config.SearchDirs {
|
||||
path += fmt.Sprintf(":%s/filters", dir)
|
||||
}
|
||||
filter.Env = os.Environ()
|
||||
filter.Env = append(filter.Env, fmt.Sprintf("PATH=%s", path))
|
||||
if pipe, err = filter.StdinPipe(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue