Resolve cleans up filesystem paths.
(path, home string)
| 8 | |
| 9 | // Resolve cleans up filesystem paths. |
| 10 | func Resolve(path, home string) string { |
| 11 | if path == "" { |
| 12 | return "" |
| 13 | } |
| 14 | if strings.HasPrefix(path, "~/") { |
| 15 | path = strings.Replace(path, "~/", "", 1) |
| 16 | return filepath.Join(home, path) |
| 17 | } |
| 18 | if filepath.IsAbs(path) { |
| 19 | return filepath.Clean(path) |
| 20 | } |
| 21 | // if using "/dir" on Windows |
| 22 | if strings.HasPrefix(path, "/") { |
| 23 | return filepath.Join(home, filepath.Clean(path)) |
| 24 | } |
| 25 | cwd, err := os.Getwd() |
| 26 | if err != nil { |
| 27 | return path |
| 28 | } |
| 29 | return filepath.Join(cwd, path) |
| 30 | } |
no outgoing calls