config: expand tilde in search directories

Will expand a user-provided custom sharedir, XDG_CONFIG_HOME and
XDG_DATA_HOME if necessary. Will not alter those strings if they do not
begin with a tilde.

Signed-off-by: Daniel Patterson <me@danielpatterson.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Daniel Patterson 2022-03-02 03:39:01 +00:00 committed by Robin Jarry
parent 0cfffaef54
commit c77a1c5d9d

View file

@ -20,6 +20,7 @@ import (
"github.com/go-ini/ini" "github.com/go-ini/ini"
"github.com/imdario/mergo" "github.com/imdario/mergo"
"github.com/kyoh86/xdg" "github.com/kyoh86/xdg"
"github.com/mitchellh/go-homedir"
"git.sr.ht/~rjarry/aerc/lib/templates" "git.sr.ht/~rjarry/aerc/lib/templates"
) )
@ -311,13 +312,20 @@ func buildDefaultDirs() []string {
// Add XDG_CONFIG_HOME and XDG_DATA_HOME // Add XDG_CONFIG_HOME and XDG_DATA_HOME
for _, v := range prefixes { for _, v := range prefixes {
if v != "" { if v != "" {
v, err := homedir.Expand(v)
if err != nil {
log.Println(err)
}
defaultDirs = append(defaultDirs, path.Join(v, "aerc")) defaultDirs = append(defaultDirs, path.Join(v, "aerc"))
} }
} }
// Add custom buildtime shareDir // Add custom buildtime shareDir
if shareDir != "" && shareDir != "/usr/local/share/aerc" { if shareDir != "" && shareDir != "/usr/local/share/aerc" {
defaultDirs = append(defaultDirs, shareDir) shareDir, err := homedir.Expand(shareDir)
if err == nil {
defaultDirs = append(defaultDirs, shareDir)
}
} }
// Add fixed fallback locations // Add fixed fallback locations