mirror of https://github.com/Hilbis/Hilbish
feat: add prependPath function (resolves #81)
parent
72cf776882
commit
94a8b4ad47
16
lua.go
16
lua.go
|
@ -32,6 +32,7 @@ func LuaInit() {
|
||||||
l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt))
|
l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt))
|
||||||
l.SetGlobal("alias", l.NewFunction(hshalias))
|
l.SetGlobal("alias", l.NewFunction(hshalias))
|
||||||
l.SetGlobal("appendPath", l.NewFunction(hshappendPath))
|
l.SetGlobal("appendPath", l.NewFunction(hshappendPath))
|
||||||
|
l.SetGlobal("prependPath", l.NewFunction(hshprependPath))
|
||||||
l.SetGlobal("exec", l.NewFunction(hshexec))
|
l.SetGlobal("exec", l.NewFunction(hshexec))
|
||||||
l.SetGlobal("goro", luar.New(l, hshgoroutine))
|
l.SetGlobal("goro", luar.New(l, hshgoroutine))
|
||||||
l.SetGlobal("timeout", luar.New(l, hshtimeout))
|
l.SetGlobal("timeout", luar.New(l, hshtimeout))
|
||||||
|
@ -226,3 +227,18 @@ func hshcomplete(L *lua.LState) int {
|
||||||
|
|
||||||
return 0
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue