github.com/jenkins-x/jx-api@v0.0.24/pkg/util/dirs.go (about) 1 package util 2 3 import ( 4 "os" 5 "path/filepath" 6 ) 7 8 // JXBinLocation finds the JX config directory and creates a bin directory inside it if it does not already exist. Returns the JX bin path 9 func JXBinLocation() (string, error) { 10 h, err := ConfigDir() 11 if err != nil { 12 return "", err 13 } 14 path := filepath.Join(h, "bin") 15 err = os.MkdirAll(path, DefaultWritePermissions) 16 if err != nil { 17 return "", err 18 } 19 return path, nil 20 } 21 22 func ConfigDir() (string, error) { 23 path := os.Getenv("JX_HOME") 24 if path != "" { 25 return path, nil 26 } 27 h := HomeDir() 28 path = filepath.Join(h, ".jx") 29 err := os.MkdirAll(path, DefaultWritePermissions) 30 if err != nil { 31 return "", err 32 } 33 return path, nil 34 } 35 36 func HomeDir() string { 37 if h := os.Getenv("HOME"); h != "" { 38 return h 39 } 40 h := os.Getenv("USERPROFILE") // windows 41 if h == "" { 42 h = "." 43 } 44 return h 45 }