From de50b62875d11394d7cb7996b55b25c2efc90772 Mon Sep 17 00:00:00 2001 From: Stephan Hradek Date: Thu, 7 Sep 2023 17:35:06 +0200 Subject: [PATCH] switch from $HOME to UserConfigDir --- main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index e65fce4..ff9b5f7 100644 --- a/main.go +++ b/main.go @@ -125,7 +125,7 @@ var flags = []cli.Flag{ &cli.StringFlag{ Name: "config", Aliases: []string{"c"}, - Value: filepath.Join(os.Getenv("HOME"), ".config/mark"), + Value: configFilePath(), Usage: "use the specified configuration file.", TakesFile: true, EnvVars: []string{"MARK_CONFIG"}, @@ -182,11 +182,11 @@ func main() { return altsrc.NewTomlSourceFromFile(filePath) } else { // Fall back to default if config is unset and path exists - _, err := os.Stat(filepath.Join(os.Getenv("HOME"), ".config/mark")) + _, err := os.Stat(configFilePath()) if os.IsNotExist(err) { return &altsrc.MapInputSource{}, nil } - return altsrc.NewTomlSourceFromFile(filepath.Join(os.Getenv("HOME"), ".config/mark")) + return altsrc.NewTomlSourceFromFile(configFilePath()) } }), EnableBashCompletion: true, @@ -515,3 +515,11 @@ func processFile( return target } + +func configFilePath() string { + fp, err := os.UserConfigDir() + if err != nil { + log.Fatal(err) + } + return filepath.Join(fp, "mark") +}