From 33ebbdfd07ff8e5bb2cd433c83b806bdbf101fd0 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Sat, 8 Oct 2022 18:17:35 -0400 Subject: [PATCH] Use os.UserHomeDir to determine home directory Go provides this since Go 1.12; no need to reinvent the wheel. --- cmd/common.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/cmd/common.go b/cmd/common.go index 692710f..f45e3d7 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -16,7 +16,6 @@ import ( "fmt" "log" "os" - "os/user" "path/filepath" "sync" @@ -41,15 +40,11 @@ var state *State var printMutex sync.Mutex func homedir() string { - home := os.Getenv("HOME") - if home != "" { - return home + homedir, err := os.UserHomeDir() + if err != nil { + panic(fmt.Errorf("unable to determine home directory: %w", err)) } - user, err := user.Current() - if err == nil { - return user.HomeDir - } - panic("Unable to determine home directory") + return homedir } func DefaultStateDir(programName string) string {