2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-06-02 02:32:03 +00:00

feat: emit hilbish.cd on fs.cd (closes #350)

This commit is contained in:
sammyette 2025-05-30 12:27:57 -04:00
parent e676c095c2
commit 049b517b88
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
4 changed files with 20 additions and 9 deletions

View File

@ -96,12 +96,23 @@ func fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return nil, err
}
path = util.ExpandHome(strings.TrimSpace(path))
oldWd, _ := os.Getwd()
abspath, err := filepath.Abs(path)
if err != nil {
return nil, err
}
err = os.Chdir(path)
if err != nil {
return nil, err
}
util.DoString(t.Runtime, fmt.Sprintf(`
local bait = require 'bait'
bait.throw('hilbish.cd', '%s', '%s')
`, abspath, oldWd))
return c.Next(), err
}

16
lua.go
View File

@ -30,19 +30,11 @@ func luaInit() {
// yes this is stupid, i know
util.DoString(l, "hilbish = require 'hilbish'")
lib.LoadLibs(l, fs.Loader)
lib.LoadLibs(l, terminal.Loader)
lib.LoadLibs(l, snail.Loader)
cmds = commander.New(l)
lib.LoadLibs(l, cmds.Loader)
hooks = bait.New(l)
hooks.SetRecoverer(func(event string, handler *bait.Listener, err interface{}) {
fmt.Println("Error in `error` hook handler:", err)
hooks.Off(event, handler)
})
lib.LoadLibs(l, hooks.Loader)
// Add Ctrl-C handler
@ -57,6 +49,14 @@ func luaInit() {
hooks.Emit("hilbish.rawInput", string(r))
}
lib.LoadLibs(l, fs.Loader)
lib.LoadLibs(l, terminal.Loader)
lib.LoadLibs(l, snail.Loader)
cmds = commander.New(l)
lib.LoadLibs(l, cmds.Loader)
// Add more paths that Lua can require from
_, err := util.DoString(l, "package.path = package.path .. " + requirePaths)
if err != nil {

View File

@ -25,5 +25,4 @@ commander.register('cd', function (args, sinks)
end
bait.throw('cd', path, oldPath)
bait.throw('hilbish.cd', absPath, oldPath)
end)

View File

@ -3,6 +3,7 @@ local bait = require 'bait'
local snail = require 'snail'
hilbish.snail = snail.new()
hilbish.snail:run 'true' -- to "initialize" snail
bait.catch('hilbish.cd', function(path)
hilbish.snail:dir(path)
end)