Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 9 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}, "")

Expand Down