diff --git a/install/install.go b/install/install.go index 1c995f3..22f9373 100644 --- a/install/install.go +++ b/install/install.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "os" - "os/user" "path/filepath" "runtime" "strings" @@ -149,14 +148,17 @@ func fishConfigDir() string { } func getConfigHomePath() string { - u, err := user.Current() - if err != nil { - return "" + homeEnv := "HOME" + switch runtime.GOOS { + case "windows": + homeEnv = "USERPROFILE" + case "plan9": + homeEnv = "home" } - + homeDir := os.Getenv(homeEnv) configHome := os.Getenv("XDG_CONFIG_HOME") if configHome == "" { - return filepath.Join(u.HomeDir, ".config") + return filepath.Join(homeDir, ".config") } return configHome } @@ -170,11 +172,15 @@ func getBinaryPath() (string, error) { } func rcFile(name string) string { - u, err := user.Current() - if err != nil { - return "" + homeEnv := "HOME" + switch runtime.GOOS { + case "windows": + homeEnv = "USERPROFILE" + case "plan9": + homeEnv = "home" } - path := filepath.Join(u.HomeDir, name) + homeDir := os.Getenv(homeEnv) + path := filepath.Join(homeDir, name) if _, err := os.Stat(path); err != nil { return "" }