fix: check if path has tilde prefix when trying to expand home

insensitive-tab^2
TorchedSammy 2022-05-01 07:20:40 -04:00
parent db437905e0
commit 30b07bc98b
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 10 additions and 3 deletions

View File

@ -153,9 +153,16 @@ func ForEach(tbl *rt.Table, cb func(key rt.Value, val rt.Value)) {
}
}
// ExpandHome expands ~ (tilde) in the path, changing it to the user home
// directory.
func ExpandHome(path string) string {
if strings.HasPrefix(path, "~") {
curuser, _ := user.Current()
homedir := curuser.HomeDir
return strings.Replace(path, "~", homedir, 1)
}
return path
}