mirror of https://github.com/Hilbis/Hilbish
feat: attempt to implement fg builtin
parent
d65b574cb2
commit
021906ae86
18
exec.go
18
exec.go
|
@ -17,6 +17,7 @@ import (
|
||||||
"hilbish/util"
|
"hilbish/util"
|
||||||
|
|
||||||
rt "github.com/arnodel/golua/runtime"
|
rt "github.com/arnodel/golua/runtime"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
"mvdan.cc/sh/v3/shell"
|
"mvdan.cc/sh/v3/shell"
|
||||||
//"github.com/yuin/gopher-lua/parse"
|
//"github.com/yuin/gopher-lua/parse"
|
||||||
"mvdan.cc/sh/v3/interp"
|
"mvdan.cc/sh/v3/interp"
|
||||||
|
@ -273,6 +274,23 @@ func execHandle(bg bool) interp.ExecHandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sh interp has "fg" as unimplemented builtin, which panics
|
||||||
|
if args[0] == "_fg" {
|
||||||
|
j := jobs.getLatest()
|
||||||
|
if j == nil || j.pid == 0 {
|
||||||
|
return interp.NewExitStatus(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
pgid, _ := syscall.Getpgid(j.pid)
|
||||||
|
|
||||||
|
// tcsetpgrp
|
||||||
|
unix.IoctlSetPointerInt(0, unix.TIOCSPGRP, pgid)
|
||||||
|
proc, _ := os.FindProcess(j.pid)
|
||||||
|
proc.Wait()
|
||||||
|
|
||||||
|
return interp.NewExitStatus(0)
|
||||||
|
}
|
||||||
|
|
||||||
// If command is defined in Lua then run it
|
// If command is defined in Lua then run it
|
||||||
luacmdArgs := rt.NewTable()
|
luacmdArgs := rt.NewTable()
|
||||||
for i, str := range args[1:] {
|
for i, str := range args[1:] {
|
||||||
|
|
Loading…
Reference in New Issue