add function to obtain home dir

This commit is contained in:
gutmet 2019-01-12 22:26:31 +01:00
parent 4ad5c8d93a
commit 2c5c9628c4

View File

@ -8,6 +8,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"os/user"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
@ -100,6 +101,15 @@ func DirsWithPrefix(path string, prefix string) ([]string, error) {
return dirs, nil 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) { func AskFor(question string) (string, error) {
fmt.Print(question + ": ") fmt.Print(question + ": ")
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)