diff --git a/exec.go b/exec.go index 36d3b16..2e0e0b1 100644 --- a/exec.go +++ b/exec.go @@ -17,7 +17,6 @@ import ( "hilbish/util" rt "github.com/arnodel/golua/runtime" - "golang.org/x/sys/unix" "mvdan.cc/sh/v3/shell" //"github.com/yuin/gopher-lua/parse" "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 luacmdArgs := rt.NewTable() for i, str := range args[1:] { diff --git a/nature/commands/fg.lua b/nature/commands/fg.lua new file mode 100644 index 0000000..a3f1451 --- /dev/null +++ b/nature/commands/fg.lua @@ -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) diff --git a/nature/commands/init.lua b/nature/commands/init.lua index 589cbd5..bba2bb6 100644 --- a/nature/commands/init.lua +++ b/nature/commands/init.lua @@ -5,3 +5,4 @@ require 'nature.commands.doc' require 'nature.commands.exit' require 'nature.commands.guide' require 'nature.commands.disown' +require 'nature.commands.fg'