From e1ae5abab93de4fa4a1bdef765fc779bed17c17b Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Mon, 29 Jun 2026 20:34:14 -0400 Subject: [PATCH] Use HOME for Barnard config path --- config/user_config.go | 8 +++----- config/user_config_test.go | 13 +++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/config/user_config.go b/config/user_config.go index d62583e..57d2508 100644 --- a/config/user_config.go +++ b/config/user_config.go @@ -7,7 +7,6 @@ import ( "github.com/pelletier/go-toml/v2" "io/ioutil" "os" - "os/user" "strconv" "strings" ) @@ -398,15 +397,14 @@ func fileExists(path string) bool { func resolvePath(path string) string { if strings.HasPrefix(path, "~/") || strings.Contains(path, "$HOME") { - usr, err := user.Current() + homeDir, err := os.UserHomeDir() if err != nil { panic(err) } - var hd = usr.HomeDir if strings.Contains(path, "$HOME") { - path = strings.Replace(path, "$HOME", hd, 1) + path = strings.Replace(path, "$HOME", homeDir, 1) } else { - path = strings.Replace(path, "~", hd, 1) + path = strings.Replace(path, "~", homeDir, 1) } } return path diff --git a/config/user_config_test.go b/config/user_config_test.go index f56279f..a82d078 100644 --- a/config/user_config_test.go +++ b/config/user_config_test.go @@ -36,3 +36,16 @@ func TestConfigBackfillsRecordingDefaults(t *testing.T) { t.Fatalf("expected admin menu f11, got %s", got) } } + +func TestConfigUsesHomeEnvironmentForDefaultPath(t *testing.T) { + dir := t.TempDir() + t.Setenv("HOME", dir) + configPath := "~/.barnard.toml" + + cfg := NewConfig(&configPath) + cfg.SaveConfig() + + if _, err := os.Stat(filepath.Join(dir, ".barnard.toml")); err != nil { + t.Fatalf("expected config to be written under HOME: %v", err) + } +}