gopkg.in/docker/docker.v23@v23.0.11/pkg/homedir/homedir_unix.go (about) 1 //go:build !windows 2 // +build !windows 3 4 package homedir // import "github.com/docker/docker/pkg/homedir" 5 6 import ( 7 "os" 8 "os/user" 9 ) 10 11 // Key returns the env var name for the user's home dir based on 12 // the platform being run on 13 func Key() string { 14 return "HOME" 15 } 16 17 // Get returns the home directory of the current user with the help of 18 // environment variables depending on the target operating system. 19 // Returned path should be used with "path/filepath" to form new paths. 20 // 21 // If linking statically with cgo enabled against glibc, ensure the 22 // osusergo build tag is used. 23 // 24 // If needing to do nss lookups, do not disable cgo or set osusergo. 25 func Get() string { 26 home := os.Getenv(Key()) 27 if home == "" { 28 if u, err := user.Current(); err == nil { 29 return u.HomeDir 30 } 31 } 32 return home 33 } 34 35 // GetShortcutString returns the string that is shortcut to user's home directory 36 // in the native shell of the platform running on. 37 func GetShortcutString() string { 38 return "~" 39 }