github.com/spinnaker/spin@v1.30.0/util/filepath.go (about) 1 package util 2 3 import ( 4 "os" 5 "strings" 6 ) 7 8 // ExpandHomeDir expands filepath with a tilde prefix. If the given filepath 9 // doesn't have a tilde this function return the filepath as it is. 10 func ExpandHomeDir(path string) (string, error) { 11 if !strings.HasPrefix(path, "~") { 12 return path, nil 13 } 14 15 home, err := os.UserHomeDir() 16 if err != nil { 17 return "", err 18 } 19 return home + strings.TrimPrefix(path, "~"), nil 20 }