From 2c5c9628c4cf19b70754038cce74f57902fabb68 Mon Sep 17 00:00:00 2001 From: gutmet Date: Sat, 12 Jan 2019 22:26:31 +0100 Subject: [PATCH] add function to obtain home dir --- goutil.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/goutil.go b/goutil.go index a0989e5..2530045 100644 --- a/goutil.go +++ b/goutil.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "os" "os/exec" + "os/user" "path/filepath" "runtime" "strings" @@ -100,6 +101,15 @@ func DirsWithPrefix(path string, prefix string) ([]string, error) { return dirs, nil } +func HomeDir() (string, error) { + d := "" + currentUser, err := user.Current() + if err == nil { + d = currentUser.HomeDir + } + return d, err +} + func AskFor(question string) (string, error) { fmt.Print(question + ": ") reader := bufio.NewReader(os.Stdin)