github.com/pquerna/agent@v2.1.8+incompatible/utils/path.go (about) 1 package utils 2 3 import ( 4 "os" 5 "os/user" 6 "strings" 7 ) 8 9 // Replaces ~/ with the users home directory, ./ with the woring directory, and 10 // replaces any parses any environment variables. 11 func NormalizeFilePath(path string) string { 12 expandedPath := os.ExpandEnv(path) 13 14 if len(expandedPath) > 2 { 15 if expandedPath[:2] == "~/" { 16 usr, _ := user.Current() 17 dir := usr.HomeDir 18 return strings.Replace(expandedPath, "~", dir, 1) 19 } else if expandedPath[:2] == "./" { 20 dir, _ := os.Getwd() 21 return strings.Replace(expandedPath, ".", dir, 1) 22 } 23 } 24 25 return expandedPath 26 }