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

比较提交

..

没有共同的提交。f9c1eced68c6e8d236465e540c72fec389659bb6 和 941902f43b4513f18148d7ad1bb0fee63a7ae269 的历史完全不同。

共有 4 个文件被更改,包括 8 次插入38 次删除

23
lua.go
查看文件

@ -3,9 +3,7 @@ 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"
@ -33,7 +31,6 @@ 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)
@ -65,9 +62,9 @@ func LuaInit() {
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?.lua' .. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?.lua'
`) `)
err := l.DoFile("preload.lua") err := l.DoFile("/usr/share/hilbish/preload.lua")
if err != nil { if err != nil {
err = l.DoFile("/usr/share/hilbish/preload.lua") err = l.DoFile("preload.lua")
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, fmt.Fprintln(os.Stderr,
"Missing preload file, builtins may be missing.") "Missing preload file, builtins may be missing.")
@ -130,19 +127,3 @@ 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
}

查看文件

@ -14,11 +14,10 @@ import (
"github.com/pborman/getopt" "github.com/pborman/getopt"
"github.com/bobappleyard/readline" "github.com/bobappleyard/readline"
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
"layeh.com/gopher-luar"
"golang.org/x/term" "golang.org/x/term"
) )
const version = "0.4.1-dev.8" const version = "0.4.0"
var ( var (
l *lua.LState l *lua.LState
@ -47,11 +46,11 @@ func main() {
// parser := argparse.NewParser("hilbish", "A shell for lua and flower lovers") // parser := argparse.NewParser("hilbish", "A shell for lua and flower lovers")
verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version") verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version")
setshflag := getopt.BoolLong("setshellenv", 'S', "Sets $SHELL to Hilbish's executed path") setshflag := getopt.BoolLong("setshellenv", 'S', "Sets $SHELL to Hilbish's executed path")
cmdflag := getopt.StringLong("command", 'c', "", "Executes a command on startup") cmdflag := getopt.StringLong("command", 'c', "", /*TODO: Help description*/ "")
configflag := getopt.StringLong("config", 'C', defaultconfpath, "Sets the path to Hilbish's config") configflag := getopt.StringLong("config", 'C', defaultconfpath, "Sets the path to Hilbish's config")
getopt.BoolLong("login", 'l', "Makes Hilbish act like a login shell") getopt.BoolLong("login", 'l', "Makes Hilbish act like a login shell")
getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell") getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell")
getopt.BoolLong("noexec", 'n', "Don't execute and only report Lua syntax errors") getopt.BoolLong("noexec", 'n', "Force Hilbish to be an interactive shell")
getopt.Parse() getopt.Parse()
loginshflag := getopt.Lookup('l').Seen() loginshflag := getopt.Lookup('l').Seen()
@ -119,7 +118,6 @@ func main() {
RunInput(*cmdflag) RunInput(*cmdflag)
if getopt.NArgs() > 0 { if getopt.NArgs() > 0 {
l.SetGlobal("args", luar.New(l, getopt.Args()))
err := l.DoFile(getopt.Arg(0)) err := l.DoFile(getopt.Arg(0))
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)

查看文件

@ -20,8 +20,8 @@ commander.register('cd', function (args)
if err == 1 then if err == 1 then
print('directory does not exist') print('directory does not exist')
end end
return err bait.throw('command.exit', err)
end else bait.throw('command.exit', 0) end
return return
end end
fs.cd(os.getenv 'HOME') fs.cd(os.getenv 'HOME')

查看文件

@ -52,17 +52,9 @@ func RunInput(input string) {
l.GetGlobal("commanding"), l.GetGlobal("commanding"),
lua.LString("__commands")), lua.LString("__commands")),
cmdArgs[0]), cmdArgs[0]),
NRet: 1, NRet: 0,
Protect: true, Protect: true,
}, luar.New(l, cmdArgs[1:])) }, luar.New(l, cmdArgs[1:]))
luaexitcode := l.Get(-1)
exitcode := lua.LNumber(0)
l.Pop(1)
if code, ok := luaexitcode.(lua.LNumber); luaexitcode != lua.LNil && ok {
exitcode = code
}
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, fmt.Fprintln(os.Stderr,
"Error in command:\n\n" + err.Error()) "Error in command:\n\n" + err.Error())
@ -70,7 +62,6 @@ func RunInput(input string) {
if cmdArgs[0] != "exit" { if cmdArgs[0] != "exit" {
HandleHistory(cmdString) HandleHistory(cmdString)
} }
hooks.Em.Emit("command.exit", exitcode)
return return
} }