mirror of https://github.com/Hilbis/Hilbish
Compare commits
8 Commits
2f809e398c
...
970fe43413
Author | SHA1 | Date |
---|---|---|
TorchedSammy | 970fe43413 | |
TorchedSammy | 11aaa0cd36 | |
TorchedSammy | 6bff669abe | |
TorchedSammy | c6edbc20af | |
TorchedSammy | 82b4fa5e7c | |
TorchedSammy | 3f1f698511 | |
TorchedSammy | 3421f286f2 | |
TorchedSammy | bfc141f655 |
|
@ -1,4 +1,6 @@
|
||||||
catch(name, cb) > Catches a hook with `name`. Runs the `cb` when it is thrown
|
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`
|
throw(name, ...args) > Throws a hook with `name` with the provided `args`
|
||||||
|
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -22,5 +22,4 @@ require (
|
||||||
)
|
)
|
||||||
|
|
||||||
replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20211022004519-f67a49cb50f5
|
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
|
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)
|
// run(cmd)
|
||||||
// Runs `cmd` in Hilbish's sh interpreter
|
// Runs `cmd` in Hilbish's sh interpreter
|
||||||
func hlrun(L *lua.LState) int {
|
func hlrun(L *lua.LState) int {
|
||||||
var exitcode uint8 = 0
|
var exitcode uint8
|
||||||
cmd := L.CheckString(1)
|
cmd := L.CheckString(1)
|
||||||
err := execCommand(cmd)
|
err := execCommand(cmd)
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,9 @@ commander.register('cd', function (args)
|
||||||
end
|
end
|
||||||
fs.cd(hilbish.home)
|
fs.cd(hilbish.home)
|
||||||
bait.throw('cd', hilbish.home)
|
bait.throw('cd', hilbish.home)
|
||||||
|
|
||||||
|
table.insert(recentDirs, 1, hilbish.home)
|
||||||
|
recentDirs[11] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
commander.register('exit', function()
|
commander.register('exit', function()
|
||||||
|
@ -72,7 +75,8 @@ These are the global Hilbish functions that are always available and not part of
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
funcdocs = f:read '*a'
|
funcdocs = f:read '*a'
|
||||||
local subdocs = table.map(fs.readdir(moddocPath), function(fname)
|
local moddocs = table.filter(fs.readdir(moddocPath), function(f) return f ~= 'index.txt' end)
|
||||||
|
local subdocs = table.map(moddocs, function(fname)
|
||||||
return lunacolors.underline(lunacolors.blue(string.gsub(fname, '.txt', '')))
|
return lunacolors.underline(lunacolors.blue(string.gsub(fname, '.txt', '')))
|
||||||
end)
|
end)
|
||||||
if subdocName == 'index' then
|
if subdocName == 'index' then
|
||||||
|
|
56
rl.go
56
rl.go
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build !hilbiline && !goreadline
|
||||||
// +build !hilbiline,!goreadline
|
// +build !hilbiline,!goreadline
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
@ -126,18 +127,53 @@ func newLineReader(prompt string) *lineReader {
|
||||||
if key.String() == fields[1] {
|
if key.String() == fields[1] {
|
||||||
// if value is a table, we need to iterate over it
|
// if value is a table, we need to iterate over it
|
||||||
// and add each value to completions
|
// and add each value to completions
|
||||||
valueTbl := value.(*lua.LTable)
|
// check if value is either a table or function
|
||||||
valueTbl.ForEach(func(key lua.LValue, value lua.LValue) {
|
if value.Type() == lua.LTTable {
|
||||||
val := value.String()
|
valueTbl := value.(*lua.LTable)
|
||||||
if val == "<file>" {
|
valueTbl.ForEach(func(key lua.LValue, value lua.LValue) {
|
||||||
// complete files
|
val := value.String()
|
||||||
completions = append(completions, readline.FilenameCompleter(query, ctx)...)
|
if val == "<file>" {
|
||||||
} else {
|
// complete files
|
||||||
if strings.HasPrefix(val, query) {
|
completions = append(completions, readline.FilenameCompleter(query, ctx)...)
|
||||||
completions = append(completions, val)
|
} 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