summaryrefslogtreecommitdiffstats
path: root/golib/filepath.go
diff options
context:
space:
mode:
Diffstat (limited to 'golib/filepath.go')
-rw-r--r--golib/filepath.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/golib/filepath.go b/golib/filepath.go
index b27ac6f..c91f63d 100644
--- a/golib/filepath.go
+++ b/golib/filepath.go
@@ -108,3 +108,17 @@ func PathNormalize(p string) string {
res = strings.Replace(res, "\\", "/", -1)
return filepath.Clean(res)
}
+
+// GetUserHome returns the user's home directory or empty string on error
+func GetUserHome() string {
+ if usr, err := user.Current(); err == nil && usr != nil && usr.HomeDir != "" {
+ return usr.HomeDir
+ }
+ for _, p := range []string{"HOME", "HomePath"} {
+ if h := os.Getenv(p); h != "" {
+ return h
+ }
+ }
+
+ return ""
+}