]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blame - vendor/github.com/fsouza/go-dockerclient/external/github.com/docker/docker/pkg/homedir/homedir.go
provider: Ensured Go 1.11 in TravisCI and README
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / fsouza / go-dockerclient / external / github.com / docker / docker / pkg / homedir / homedir.go
CommitLineData
9b12e4fe
JC
1package homedir
2
3import (
4 "os"
5 "runtime"
6
7 "github.com/fsouza/go-dockerclient/external/github.com/opencontainers/runc/libcontainer/user"
8)
9
10// Key returns the env var name for the user's home dir based on
11// the platform being run on
12func Key() string {
13 if runtime.GOOS == "windows" {
14 return "USERPROFILE"
15 }
16 return "HOME"
17}
18
19// Get returns the home directory of the current user with the help of
20// environment variables depending on the target operating system.
21// Returned path should be used with "path/filepath" to form new paths.
22func Get() string {
23 home := os.Getenv(Key())
24 if home == "" && runtime.GOOS != "windows" {
25 if u, err := user.CurrentUser(); err == nil {
26 return u.Home
27 }
28 }
29 return home
30}
31
32// GetShortcutString returns the string that is shortcut to user's home directory
33// in the native shell of the platform running on.
34func GetShortcutString() string {
35 if runtime.GOOS == "windows" {
36 return "%USERPROFILE%" // be careful while using in format functions
37 }
38 return "~"
39}