mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "970fe43413337a7d8f5cca5a5cf336429add5cfd" and "2f809e398cadeb869c301dc8df3887658dcb1194" have entirely different histories.
970fe43413
...
2f809e398c
|
@ -1,6 +1,4 @@
|
|||
catch(name, cb) > Catches a hook with `name`. Runs the `cb` when it is thrown
|
||||
|
||||
catchOnce(name, cb) > Same as catch, but only runs the `cb` once and then removes the hook
|
||||
|
||||
throw(name, ...args) > Throws a hook with `name` with the provided `args`
|
||||
|
||||
|
|
1
go.mod
1
go.mod
|
@ -22,4 +22,5 @@ require (
|
|||
)
|
||||
|
||||
replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20211022004519-f67a49cb50f5
|
||||
|
||||
replace github.com/maxlandon/readline => github.com/Rosettea/readline-1 v0.1.0-beta.0.20211207003625-341c7985ad7d
|
||||
|
|
|
@ -55,7 +55,7 @@ func hilbishLoader(L *lua.LState) int {
|
|||
// run(cmd)
|
||||
// Runs `cmd` in Hilbish's sh interpreter
|
||||
func hlrun(L *lua.LState) int {
|
||||
var exitcode uint8
|
||||
var exitcode uint8 = 0
|
||||
cmd := L.CheckString(1)
|
||||
err := execCommand(cmd)
|
||||
|
||||
|
|
|
@ -37,9 +37,6 @@ commander.register('cd', function (args)
|
|||
end
|
||||
fs.cd(hilbish.home)
|
||||
bait.throw('cd', hilbish.home)
|
||||
|
||||
table.insert(recentDirs, 1, hilbish.home)
|
||||
recentDirs[11] = nil
|
||||
end)
|
||||
|
||||
commander.register('exit', function()
|
||||
|
@ -75,8 +72,7 @@ These are the global Hilbish functions that are always available and not part of
|
|||
return
|
||||
end
|
||||
funcdocs = f:read '*a'
|
||||
local moddocs = table.filter(fs.readdir(moddocPath), function(f) return f ~= 'index.txt' end)
|
||||
local subdocs = table.map(moddocs, function(fname)
|
||||
local subdocs = table.map(fs.readdir(moddocPath), function(fname)
|
||||
return lunacolors.underline(lunacolors.blue(string.gsub(fname, '.txt', '')))
|
||||
end)
|
||||
if subdocName == 'index' then
|
||||
|
|
56
rl.go
56
rl.go
|
@ -1,4 +1,3 @@
|
|||
//go:build !hilbiline && !goreadline
|
||||
// +build !hilbiline,!goreadline
|
||||
|
||||
package main
|
||||
|
@ -127,53 +126,18 @@ func newLineReader(prompt string) *lineReader {
|
|||
if key.String() == fields[1] {
|
||||
// if value is a table, we need to iterate over it
|
||||
// and add each value to completions
|
||||
// check if value is either a table or function
|
||||
if value.Type() == lua.LTTable {
|
||||
valueTbl := value.(*lua.LTable)
|
||||
valueTbl.ForEach(func(key lua.LValue, value lua.LValue) {
|
||||
val := value.String()
|
||||
if val == "<file>" {
|
||||
// complete files
|
||||
completions = append(completions, readline.FilenameCompleter(query, ctx)...)
|
||||
} else {
|
||||
if strings.HasPrefix(val, query) {
|
||||
completions = append(completions, val)
|
||||
}
|
||||
valueTbl := value.(*lua.LTable)
|
||||
valueTbl.ForEach(func(key lua.LValue, value lua.LValue) {
|
||||
val := value.String()
|
||||
if val == "<file>" {
|
||||
// complete files
|
||||
completions = append(completions, readline.FilenameCompleter(query, ctx)...)
|
||||
} else {
|
||||
if strings.HasPrefix(val, query) {
|
||||
completions = append(completions, val)
|
||||
}
|
||||
})
|
||||
} else if value.Type() == lua.LTFunction {
|
||||
// if value is a function, we need to call it
|
||||
// and add each value to completions
|
||||
// completionsCtx is the context we pass to the function,
|
||||
// removing 2 fields from the fields array
|
||||
completionsCtx := strings.Join(fields[2:], " ")
|
||||
err := l.CallByParam(lua.P{
|
||||
Fn: value,
|
||||
NRet: 1,
|
||||
Protect: true,
|
||||
}, lua.LString(query), lua.LString(completionsCtx))
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
luacompleteTable := l.Get(-1)
|
||||
l.Pop(1)
|
||||
|
||||
// just check if its actually a table and add it to the completions
|
||||
if cmpTbl, ok := luacompleteTable.(*lua.LTable); ok {
|
||||
cmpTbl.ForEach(func(key lua.LValue, value lua.LValue) {
|
||||
val := value.String()
|
||||
if strings.HasPrefix(val, query) {
|
||||
completions = append(completions, val)
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// throw lua error
|
||||
// complete.cmdname: error message...
|
||||
l.RaiseError("complete." + fields[0] + ": completion value is not a table or function")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue