diff --git a/internal/config/config.go b/internal/config/config.go index 4a5dc23..2f22243 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -21,6 +21,9 @@ type HostConfig struct { } func GetConfigDir() (string, error) { + if xdgConfigHome := os.Getenv("XDG_CONFIG_HOME"); xdgConfigHome != "" { + return filepath.Join(xdgConfigHome, "fgj"), nil + } home, err := os.UserHomeDir() if err != nil { return "", err diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 6912963..3d55ee9 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -75,6 +75,20 @@ func TestGetConfigDir(t *testing.T) { } } +func TestGetConfigDir_XDG(t *testing.T) { + t.Setenv("XDG_CONFIG_HOME", "/custom/config") + + dir, err := GetConfigDir() + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + expected := "/custom/config/fgj" + if dir != expected { + t.Errorf("Expected %q, got %q", expected, dir) + } +} + func TestGetConfigPath(t *testing.T) { path, err := GetConfigPath() if err != nil {