From 23593c3d2009ca87072c73f0d5050f9b2de638d4 Mon Sep 17 00:00:00 2001 From: filoozom Date: Sun, 2 Mar 2014 16:07:12 +0100 Subject: [PATCH] Update getHomeDir() to use "os/user" os.Getenv("HOME") doesn't work properly on Windows (and maybe other systems?) and the package "os/user" gives us a convenient way to find the home directory for every OS. --- main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 069c6dd6..f9c7416e 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( _ "net/http/pprof" "os" "os/exec" + "os/user" "path" "runtime" "runtime/debug" @@ -561,9 +562,13 @@ func expandTilde(p string) string { } func getHomeDir() string { - home := os.Getenv("HOME") - if home == "" { + usr, err := user.Current() + if err != nil { + fatalln(err) + } + + if usr.HomeDir == "" { fatalln("No home directory?") } - return home + return usr.HomeDir }