From 30b07bc98b76cd8f87d7178379cafc4e86e23e17 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sun, 1 May 2022 07:20:40 -0400 Subject: [PATCH] fix: check if path has tilde prefix when trying to expand home --- util/util.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/util/util.go b/util/util.go index 4bfecc9..713ea6a 100644 --- a/util/util.go +++ b/util/util.go @@ -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 { - curuser, _ := user.Current() - homedir := curuser.HomeDir + if strings.HasPrefix(path, "~") { + curuser, _ := user.Current() + homedir := curuser.HomeDir - return strings.Replace(path, "~", homedir, 1) + return strings.Replace(path, "~", homedir, 1) + } + + return path } +