fix: dont append to path if dir is already there (resolves #52)

pull/59/head
sammy 2021-05-15 22:23:21 -04:00
parent 2c2eb8d69a
commit 0afca3d4f6
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
1 changed files with 7 additions and 3 deletions

10
lua.go
View File

@ -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
}