aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/aerc.conf8
-rw-r--r--config/config.go39
2 files changed, 36 insertions, 11 deletions
diff --git a/config/aerc.conf b/config/aerc.conf
index 631a5667..a7628e39 100644
--- a/config/aerc.conf
+++ b/config/aerc.conf
@@ -105,8 +105,8 @@ next-message-on-delete=true
# list of directories. If this is unset or if a styleset cannot be found, the
# following paths will be used as a fallback in that order:
#
-# ~/.config/aerc/stylesets
-# ~/.local/share/aerc/stylesets
+# ${XDG_CONFIG_HOME:-~/.config}/aerc/stylesets
+# ${XDG_DATA_HOME:-~/.local/share}/aerc/stylesets
# /usr/local/share/aerc/stylesets
# /usr/share/aerc/stylesets
#
@@ -251,8 +251,8 @@ new-email=
# list of directories. If this is unset or if a template cannot be found, the
# following paths will be used as a fallback in that order:
#
-# ~/.config/aerc/templates
-# ~/.local/share/aerc/templates
+# ${XDG_CONFIG_HOME:-~/.config}/aerc/templates
+# ${XDG_DATA_HOME:-~/.local/share}/aerc/templates
# /usr/local/share/aerc/templates
# /usr/share/aerc/templates
#
diff --git a/config/config.go b/config/config.go
index d2512d2f..f5d43ec4 100644
--- a/config/config.go
+++ b/config/config.go
@@ -297,13 +297,38 @@ func parseCredential(cred, command string) (string, error) {
return u.String(), nil
}
-var defaultDirs []string = []string{
- path.Join(xdg.ConfigHome(), "aerc"),
- path.Join(xdg.DataHome(), "aerc"),
- "/usr/local/share/aerc",
- "/usr/share/aerc",
+// Set at build time
+var shareDir string
+
+func buildDefaultDirs() []string {
+ var defaultDirs []string
+
+ prefixes := []string{
+ xdg.ConfigHome(),
+ xdg.DataHome(),
+ }
+
+ // Add XDG_CONFIG_HOME and XDG_DATA_HOME
+ for _, v := range prefixes {
+ if v != "" {
+ defaultDirs = append(defaultDirs, path.Join(v, "aerc"))
+ }
+ }
+
+ // Add custom buildtime shareDir
+ if shareDir != "" && shareDir != "/usr/local/share/aerc" {
+ defaultDirs = append(defaultDirs, shareDir)
+ }
+
+ // Add fixed fallback locations
+ defaultDirs = append(defaultDirs, "/usr/local/share/aerc")
+ defaultDirs = append(defaultDirs, "/usr/share/aerc")
+
+ return defaultDirs
}
+var searchDirs = buildDefaultDirs()
+
func installTemplate(root, name string) error {
var err error
if _, err = os.Stat(root); os.IsNotExist(err) {
@@ -313,7 +338,7 @@ func installTemplate(root, name string) error {
}
}
var data []byte
- for _, dir := range defaultDirs {
+ for _, dir := range searchDirs {
data, err = ioutil.ReadFile(path.Join(dir, name))
if err == nil {
break
@@ -464,7 +489,7 @@ func (config *AercConfig) LoadConfig(file *ini.File) error {
}
// append default paths to template-dirs and styleset-dirs
- for _, dir := range defaultDirs {
+ for _, dir := range searchDirs {
config.Ui.StyleSetDirs = append(
config.Ui.StyleSetDirs, path.Join(dir, "stylesets"),
)