feat: appendpath function

pull/42/head
Devin Singh 2021-04-28 17:09:10 -05:00
parent 4476a96eec
commit 786b95c266
No known key found for this signature in database
GPG Key ID: 7EA319C5D57B6506
2 changed files with 12 additions and 19 deletions

View File

@ -24,22 +24,6 @@ var exports = map[string]lua.LGFunction{
"cd": cd,
"mkdir": mkdir,
"stat": stat,
"appendpath": appendpath,
}
func appendpath(L *lua.LState) int {
path := L.ToString(1)
os.Setenv("PATH", os.Getenv("PATH")+":"+path)
// cmd := exec.Command("export PATH=" + os.Getenv("PATH") + ":" + path)
// shell.execCommand("export PATH=" + os.Getenv("PATH") + ":" + path)
// fmt.Println(cmd.String())
// err := cmd.Run()
// if err != nil {
// LuaErr(L, 1)
// }
return 0
}
func cd(L *lua.LState) int {

9
lua.go
View File

@ -27,6 +27,7 @@ func LuaInit(confpath string) {
l.SetGlobal("prompt", l.NewFunction(hshprompt))
l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt))
l.SetGlobal("alias", l.NewFunction(hshalias))
l.SetGlobal("appendpath", l.NewFunction(hsappendpath))
// Add fs module to Lua
l.PreloadModule("fs", lfs.Loader)
@ -99,3 +100,11 @@ func hshalias(L *lua.LState) int {
return 1
}
func hsappendpath(L *lua.LState) int {
path := L.ToString(1)
os.Setenv("PATH", os.Getenv("PATH")+":"+path)
return 0
}