mirror of https://github.com/Hilbis/Hilbish
feat: add exec function
this is basically the `exec` "command" in sh itll replace hilbish with whatever provided simple usage: exec 'sleep 100'pull/59/head
parent
1bacbfc778
commit
8f94990fc3
19
lua.go
19
lua.go
|
@ -3,7 +3,9 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"hilbish/golibs/bait"
|
"hilbish/golibs/bait"
|
||||||
"hilbish/golibs/commander"
|
"hilbish/golibs/commander"
|
||||||
|
@ -31,6 +33,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("exec", l.NewFunction(hshexec))
|
||||||
|
|
||||||
// Add fs module to Lua
|
// Add fs module to Lua
|
||||||
l.PreloadModule("fs", fs.Loader)
|
l.PreloadModule("fs", fs.Loader)
|
||||||
|
@ -127,3 +130,19 @@ func hshappendPath(L *lua.LState) int {
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hshexec(L *lua.LState) int {
|
||||||
|
cmd := L.CheckString(1)
|
||||||
|
cmdArgs, _ := splitInput(cmd)
|
||||||
|
cmdPath, err := exec.LookPath(cmdArgs[0])
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
// if we get here, cmdPath will be nothing
|
||||||
|
// therefore nothing will run
|
||||||
|
}
|
||||||
|
|
||||||
|
// syscall.Exec requires an absolute path to a binary
|
||||||
|
// path, args, string slice of environments
|
||||||
|
syscall.Exec(cmdPath, cmdArgs, os.Environ())
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue