mirror of https://github.com/Hilbis/Hilbish
refactor: implement fg in lua
parent
4c8cb686a0
commit
43dc00c120
20
exec.go
20
exec.go
|
@ -17,7 +17,6 @@ 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"
|
||||||
|
@ -274,25 +273,6 @@ 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)
|
|
||||||
hshPgid, _ := syscall.Getpgid(os.Getpid())
|
|
||||||
|
|
||||||
// tcsetpgrp
|
|
||||||
unix.IoctlSetPointerInt(0, unix.TIOCSPGRP, pgid)
|
|
||||||
proc, _ := os.FindProcess(j.pid)
|
|
||||||
proc.Wait()
|
|
||||||
unix.IoctlSetPointerInt(0, unix.TIOCSPGRP, hshPgid)
|
|
||||||
|
|
||||||
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:] {
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
local commander = require 'commander'
|
||||||
|
|
||||||
|
commander.register('fg', function()
|
||||||
|
local job = hilbish.jobs.last()
|
||||||
|
if not job then
|
||||||
|
print 'fg: no last job'
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local err = job.foreground() -- waits for job; blocks
|
||||||
|
if err then
|
||||||
|
print('fg: ' .. err)
|
||||||
|
return 2
|
||||||
|
end
|
||||||
|
end)
|
|
@ -5,3 +5,4 @@ require 'nature.commands.doc'
|
||||||
require 'nature.commands.exit'
|
require 'nature.commands.exit'
|
||||||
require 'nature.commands.guide'
|
require 'nature.commands.guide'
|
||||||
require 'nature.commands.disown'
|
require 'nature.commands.disown'
|
||||||
|
require 'nature.commands.fg'
|
||||||
|
|
Loading…
Reference in New Issue