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:
parent
e676c095c2
commit
049b517b88
@ -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
16
lua.go
@ -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 {
|
||||
|
@ -25,5 +25,4 @@ commander.register('cd', function (args, sinks)
|
||||
end
|
||||
|
||||
bait.throw('cd', path, oldPath)
|
||||
bait.throw('hilbish.cd', absPath, oldPath)
|
||||
end)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user