From 0afca3d4f6a486b9491dfba7a0f743e64fe2d99e Mon Sep 17 00:00:00 2001 From: sammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sat, 15 May 2021 22:23:21 -0400 Subject: [PATCH] fix: dont append to path if dir is already there (resolves #52) --- lua.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lua.go b/lua.go index fb5554a..367dd89 100644 --- a/lua.go +++ b/lua.go @@ -123,10 +123,14 @@ func hshalias(L *lua.LState) int { } func hshappendPath(L *lua.LState) int { - path := L.CheckString(1) - path = strings.Replace(path, "~", curuser.HomeDir, 1) + dir := L.CheckString(1) + dir = strings.Replace(dir, "~", curuser.HomeDir, 1) + pathenv := os.Getenv("PATH") - os.Setenv("PATH", os.Getenv("PATH") + ":" + path) + // if dir isnt already in $PATH, add it + if !strings.Contains(pathenv, dir) { + os.Setenv("PATH", pathenv + ":" + dir) + } return 0 }