2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-07-05 18:42:04 +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}
println(typeName, parentMod, interfaces)
return dps
}
@ -437,10 +436,8 @@ provided by Hilbish.
interfaceModules[modname].Types = append(interfaceModules[modname].Types, piece)
}
println(mod)
fmt.Println(filteredTypePieces)
if newDoc, ok := docs[mod]; ok {
println("fuck")
oldMod := docs[mod]
newDoc.Types = append(filteredTypePieces, oldMod.Types...)
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.
### Methods
#### run(command, streams)
Runs a shell command. Works the same as `hilbish.run`.
#### 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.
#### 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 = {}
--- 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.
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
return snail

View File

@ -32,6 +32,7 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
snailMethods := rt.NewTable()
snailFuncs := map[string]util.LuaExport{
"run": {snailrun, 3, false},
"dir": {snaildir, 2, false},
}
util.SetExports(rtm, snailMethods, snailFuncs)
@ -63,7 +64,9 @@ func snailnew(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// #member
// 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) {
if err := c.CheckNArgs(2); err != nil {
return nil, err
@ -92,7 +95,7 @@ func snailrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
}
case rt.NilType: // noop
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
@ -133,6 +136,31 @@ func snailrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
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 {
if v == rt.NilValue {
return nil

View File

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

View File

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

View File

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