2
3
镜像自地址 https://github.com/sammy-ette/Hilbish 已同步 2025-08-10 02:52:03 +00:00

refactor: implement fg in lua

这个提交包含在:
TorchedSammy 2022-05-24 18:07:31 -04:00
父节点 4c8cb686a0
当前提交 43dc00c120
签署人:: sammyette
GPG 密钥 ID: 904FC49417B44DCD
共有 3 个文件被更改,包括 16 次插入20 次删除

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:] {

15
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)

查看文件

@ -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'