From 2ea1bff59d73940f87b3a75805e699c905f3befb Mon Sep 17 00:00:00 2001 From: Romain Bertrand Date: Thu, 12 Mar 2026 15:44:24 +0100 Subject: [PATCH] fix: respect $XDG_CONFIG_HOME --- internal/config/config.go | 3 +++ internal/config/config_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+) 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 {