diff --git a/lua.go b/lua.go index bf2d872..90f89ee 100644 --- a/lua.go +++ b/lua.go @@ -32,6 +32,7 @@ func LuaInit() { l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt)) l.SetGlobal("alias", l.NewFunction(hshalias)) l.SetGlobal("appendPath", l.NewFunction(hshappendPath)) + l.SetGlobal("prependPath", l.NewFunction(hshprependPath)) l.SetGlobal("exec", l.NewFunction(hshexec)) l.SetGlobal("goro", luar.New(l, hshgoroutine)) l.SetGlobal("timeout", luar.New(l, hshtimeout)) @@ -226,3 +227,18 @@ func hshcomplete(L *lua.LState) int { return 0 } + +// prependPath(dir) +// Prepends `dir` to $PATH +func hshprependPath(L *lua.LState) int { + dir := L.CheckString(1) + dir = strings.Replace(dir, "~", curuser.HomeDir, 1) + pathenv := os.Getenv("PATH") + + // if dir isnt already in $PATH, add in + if !strings.Contains(pathenv, dir) { + os.Setenv("PATH", dir + string(os.PathListSeparator) + pathenv) + } + + return 0 +}