Skip to content

Commit b0a7c5f

Browse files
committed
feat(config): use XDG_CONFIG_HOME if set on macOS, fixes #11
1 parent 8aa06cf commit b0a7c5f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

internal/paths/paths.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ func GetConfigDir() string {
2121
return filepath.Join(homeDir, "AppData", "Roaming", "xytz")
2222

2323
case "darwin":
24+
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
25+
if xdgConfigHome != "" {
26+
return filepath.Join(xdgConfigHome, "xytz")
27+
}
28+
2429
return filepath.Join(homeDir, "Library", "Application Support", "xytz")
2530

2631
default:

internal/paths/paths_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,22 @@ func TestPlatformSpecificPaths(t *testing.T) {
130130
t.Errorf("GetDataDir() = %q, expected XDG_DATA_HOME to be respected", dir)
131131
}
132132
}
133+
134+
if runtime.GOOS == "darwin" {
135+
t.Run("XDG_CONFIG_HOME respected on darwin", func(t *testing.T) {
136+
t.Setenv("XDG_CONFIG_HOME", "/custom/config")
137+
dir := GetConfigDir()
138+
if dir != "/custom/config/xytz" {
139+
t.Errorf("GetConfigDir() = %q, expected XDG_CONFIG_HOME to be respected on darwin", dir)
140+
}
141+
})
142+
143+
t.Run("XDG_DATA_HOME respected on darwin", func(t *testing.T) {
144+
t.Setenv("XDG_DATA_HOME", "/custom/data")
145+
dir := GetDataDir()
146+
if dir != "/custom/data/xytz" {
147+
t.Errorf("GetDataDir() = %q, expected XDG_DATA_HOME to be respected on darwin", dir)
148+
}
149+
})
150+
}
133151
}

0 commit comments

Comments
 (0)