2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-07-05 10:32:03 +00:00

Compare commits

...

4 Commits

7 changed files with 54 additions and 15 deletions

View File

@ -204,7 +204,6 @@ func setupDocType(mod string, typ *doc.Type) *docPiece {
} }
typeTable[strings.ToLower(typeName)] = []string{parentMod, interfaces} typeTable[strings.ToLower(typeName)] = []string{parentMod, interfaces}
println(typeName, parentMod, interfaces)
return dps return dps
} }
@ -437,10 +436,8 @@ provided by Hilbish.
interfaceModules[modname].Types = append(interfaceModules[modname].Types, piece) interfaceModules[modname].Types = append(interfaceModules[modname].Types, piece)
} }
println(mod)
fmt.Println(filteredTypePieces) fmt.Println(filteredTypePieces)
if newDoc, ok := docs[mod]; ok { if newDoc, ok := docs[mod]; ok {
println("fuck")
oldMod := docs[mod] oldMod := docs[mod]
newDoc.Types = append(filteredTypePieces, oldMod.Types...) newDoc.Types = append(filteredTypePieces, oldMod.Types...)
newDoc.Docs = append(filteredPieces, oldMod.Docs...) newDoc.Docs = append(filteredPieces, oldMod.Docs...)

View File

@ -40,6 +40,11 @@ This function has no parameters.
A Snail is a shell script interpreter instance. A Snail is a shell script interpreter instance.
### Methods ### Methods
#### run(command, streams) #### dir(path)
Runs a shell command. Works the same as `hilbish.run`. Changes the directory of the snail instance.
The interpreter keeps its set directory even when the Hilbish process changes
directory, so this should be called on the `hilbish.cd` hook.
#### run(command, streams)
Runs a shell command. Works the same as `hilbish.run`, but only accepts a table of streams.

View File

@ -2,10 +2,15 @@
local snail = {} local snail = {}
--- Changes the directory of the snail instance.
--- The interpreter keeps its set directory even when the Hilbish process changes
--- directory, so this should be called on the `hilbish.cd` hook.
function snail:dir(path) end
--- Creates a new Snail instance. --- Creates a new Snail instance.
function snail.new() end function snail.new() end
--- Runs a shell command. Works the same as `hilbish.run`. --- Runs a shell command. Works the same as `hilbish.run`, but only accepts a table of streams.
function snail:run(command, streams) end function snail:run(command, streams) end
return snail return snail

View File

@ -32,6 +32,7 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
snailMethods := rt.NewTable() snailMethods := rt.NewTable()
snailFuncs := map[string]util.LuaExport{ snailFuncs := map[string]util.LuaExport{
"run": {snailrun, 3, false}, "run": {snailrun, 3, false},
"dir": {snaildir, 2, false},
} }
util.SetExports(rtm, snailMethods, snailFuncs) util.SetExports(rtm, snailMethods, snailFuncs)
@ -63,7 +64,9 @@ func snailnew(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// #member // #member
// run(command, streams) // run(command, streams)
// Runs a shell command. Works the same as `hilbish.run`. // Runs a shell command. Works the same as `hilbish.run`, but only accepts a table of streams.
// #param command string
// #param streams table
func snailrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func snailrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.CheckNArgs(2); err != nil { if err := c.CheckNArgs(2); err != nil {
return nil, err return nil, err
@ -92,7 +95,7 @@ func snailrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
case rt.NilType: // noop case rt.NilType: // noop
default: default:
return nil, errors.New("expected 3rd arg to either be a table or a boolean") return nil, errors.New("expected 3rd arg to be a table")
} }
var newline bool var newline bool
@ -133,6 +136,31 @@ func snailrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.PushingNext1(t.Runtime, rt.TableValue(runnerRet)), nil return c.PushingNext1(t.Runtime, rt.TableValue(runnerRet)), nil
} }
// #member
// dir(path)
// Changes the directory of the snail instance.
// The interpreter keeps its set directory even when the Hilbish process changes
// directory, so this should be called on the `hilbish.cd` hook.
// #param path string Has to be an absolute path.
func snaildir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.CheckNArgs(2); err != nil {
return nil, err
}
s, err := snailArg(c, 0)
if err != nil {
return nil, err
}
dir, err := c.StringArg(1)
if err != nil {
return nil, err
}
interp.Dir(dir)(s.runner)
return c.Next(), nil
}
func handleStream(v rt.Value, strms *util.Streams, errStream, inStream bool) error { func handleStream(v rt.Value, strms *util.Streams, errStream, inStream bool) error {
if v == rt.NilValue { if v == rt.NilValue {
return nil return nil

View File

@ -17,11 +17,13 @@ commander.register('cd', function (args, sinks)
sinks.out:writeln(path) sinks.out:writeln(path)
end end
local absPath = fs.abs(path)
local ok, err = pcall(function() fs.cd(path) end) local ok, err = pcall(function() fs.cd(path) end)
if not ok then if not ok then
sinks.out:writeln(err) sinks.out:writeln(err)
return 1 return 1
end end
bait.throw('cd', path, oldPath) bait.throw('cd', path, oldPath)
bait.throw('hilbish.cd', fs.abs(path), oldPath) bait.throw('hilbish.cd', absPath, oldPath)
end) end)

View File

@ -48,11 +48,11 @@ end
--- @param dir string --- @param dir string
function dirs.push(dir) function dirs.push(dir)
dirs.recentDirs[dirs.recentSize + 1] = nil dirs.recentDirs[dirs.recentSize + 1] = nil
if dirs.recentDirs[#dirs.recentDirs - 1] ~= d then if dirs.recentDirs[#dirs.recentDirs - 1] ~= dir then
ok, d = pcall(fs.abs, d) local ok, dir = pcall(fs.abs, dir)
assert(ok, 'could not turn "' .. d .. '"into an absolute path') assert(ok, 'could not turn "' .. dir .. '"into an absolute path')
table.insert(dirs.recentDirs, 1, d) table.insert(dirs.recentDirs, 1, dir)
end end
end end

View File

@ -1,9 +1,11 @@
-- @module hilbish -- @module hilbish
local hilbish = require 'hilbish' local bait = require 'bait'
local snail = require 'snail' local snail = require 'snail'
hilbish.snail = snail.new() hilbish.snail = snail.new()
bait.catch('hilbish.cd', function(path)
hilbish.snail:dir(path)
end)
--- Runs `cmd` in Hilbish's shell script interpreter. --- Runs `cmd` in Hilbish's shell script interpreter.
--- The `streams` parameter specifies the output and input streams the command should use. --- The `streams` parameter specifies the output and input streams the command should use.
--- For example, to write command output to a sink. --- For example, to write command output to a sink.