diff --git a/internal/config/config.go b/internal/config/config.go index 979b4d5..9fe9c08 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -117,6 +117,18 @@ func New(configPath string, pager string, previewFeeds []string, version string) } configPath = filepath.Join(userConfigDir, DefaultConfigDirName, DefaultConfigFileName) + + // Check XDG_CONFIG_HOME, but fallback to default config dir for OS if the config file doesn't exist there + xdgConfigHome := os.Getenv("XDG_CONFIG_HOME") + if xdgConfigHome != "" { + tmpConfPath := filepath.Join(xdgConfigHome, DefaultConfigDirName, DefaultConfigFileName) + _, err := os.Stat(tmpConfPath) + if err != nil && !os.IsNotExist(err) { + return nil, err + } else if err == nil { + configPath = tmpConfPath + } + } } else { configPath = updateConfigPathIfDir(configPath) } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 173c446..a2e8f65 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -27,6 +27,15 @@ func TestNewDefault(t *testing.T) { test.Equal(t, fmt.Sprintf("%s/nom/", ucd), c.ConfigDir, "Wrong default ConfigDir set") } +func TestNewDefaultWithXDGConfigHome(t *testing.T) { + configHome := "/home/nommer/.config" + os.Setenv("XDG_CONFIG_HOME", configHome) + c, _ := New("", "", []string{}, "") + + test.Equal(t, fmt.Sprintf("%s/nom/config.yml", configHome), c.ConfigPath, "Wrong default XDG set") + test.Equal(t, fmt.Sprintf("%s/nom/", configHome), c.ConfigDir, "Wrong XDG ConfigDir set") +} + func TestConfigCustomPath(t *testing.T) { c, _ := New("foo/bar.yml", "", []string{}, "")