HomeDirExpand tries to expand the tilde (~) in the front of a path to a fullpath directory.
(path string)
| 52 | // HomeDirExpand tries to expand the tilde (~) in the front of a path |
| 53 | // to a fullpath directory. |
| 54 | func HomeDirExpand(path string) string { |
| 55 | usr, err := user.Current() |
| 56 | if err != nil { |
| 57 | return path |
| 58 | } |
| 59 | |
| 60 | if path == "~" { |
| 61 | return usr.HomeDir |
| 62 | } else if strings.HasPrefix(path, "~/") { |
| 63 | return filepath.Join(usr.HomeDir, strings.TrimPrefix(path, "~/")) |
| 64 | } |
| 65 | |
| 66 | return path |
| 67 | } |
| 68 | |
| 69 | // Exist return if file or path is exist. |
| 70 | func Exist(path string) bool { |
no outgoing calls