expands home directory in file paths. ~someuser/tmp will not be expanded.
(p string)
| 203 | // expands home directory in file paths. |
| 204 | // ~someuser/tmp will not be expanded. |
| 205 | func expandHome(p string) string { |
| 206 | if strings.HasPrefix(p, "~/") || strings.HasPrefix(p, "~\\") { |
| 207 | home := os.Getenv("HOME") |
| 208 | if home == "" { |
| 209 | if usr, err := user.Current(); err == nil { |
| 210 | home = usr.HomeDir |
| 211 | } |
| 212 | } |
| 213 | if home != "" { |
| 214 | p = home + p[1:] |
| 215 | } |
| 216 | } |
| 217 | return filepath.Clean(p) |
| 218 | } |
no outgoing calls
no test coverage detected