mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "587d08773f7c11e71b66fad1b8cb78adcf5cd33e" and "226605a996290f84dd0276c3d05facde9353ba82" have entirely different histories.
587d08773f
...
226605a996
|
@ -48,15 +48,6 @@ includes git commit, branch, and (new!!) release name.
|
|||
foreground and backgrounds a job respectively.
|
||||
- Friendlier functions to the `hilbish.runner` interface, which also allow
|
||||
having and using multiple runners.
|
||||
- A few new functions to the `fs` module:
|
||||
- `fs.basename(path)` gets the basename of path
|
||||
- `fs.dir(path)` gets the directory part of path
|
||||
- `fs.glob(pattern)` globs files and directories based on patterns
|
||||
- .. and 2 properties
|
||||
- `fs.pathSep` is the separator for filesystem paths and directories
|
||||
- `fs.pathListSep` is the separator for $PATH env entries
|
||||
- Lua modules located in `hilbish.userDir.data .. '/hilbish/start'` (like `~/.local/share/hilbish/start/foo/init.lua`)
|
||||
will be ran on startup
|
||||
|
||||
### Changed
|
||||
- **Breaking Change:** Upgraded to Lua 5.4.
|
||||
|
|
|
@ -1,16 +1,7 @@
|
|||
abs(path) > Gives an absolute version of `path`.
|
||||
|
||||
basename(path) > Gives the basename of `path`. For the rules,
|
||||
see Go's filepath.Base
|
||||
|
||||
cd(dir) > Changes directory to `dir`
|
||||
|
||||
dir(path) > Returns the directory part of `path`. For the rules, see Go's
|
||||
filepath.Dir
|
||||
|
||||
glob(pattern) > Glob all files and directories that match the pattern.
|
||||
For the rules, see Go's filepath.Glob
|
||||
|
||||
mkdir(name, recursive) > Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
|
||||
|
||||
readdir(dir) > Returns a table of files in `dir`
|
||||
|
|
|
@ -6,22 +6,10 @@ local fs = {}
|
|||
--- @param path string
|
||||
function fs.abs(path) end
|
||||
|
||||
--- Gives the basename of `path`. For the rules,
|
||||
--- see Go's filepath.Base
|
||||
function fs.basename() end
|
||||
|
||||
--- Changes directory to `dir`
|
||||
--- @param dir string
|
||||
function fs.cd(dir) end
|
||||
|
||||
--- Returns the directory part of `path`. For the rules, see Go's
|
||||
--- filepath.Dir
|
||||
function fs.dir() end
|
||||
|
||||
--- Glob all files and directories that match the pattern.
|
||||
--- For the rules, see Go's filepath.Glob
|
||||
function fs.glob() end
|
||||
|
||||
--- Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
|
||||
--- @param name string
|
||||
--- @param recursive boolean
|
||||
|
|
13
exec.go
13
exec.go
|
@ -116,17 +116,12 @@ func runInput(input string, priv bool) {
|
|||
}
|
||||
} else {
|
||||
// can only be a string or function so
|
||||
var runnerErr error
|
||||
input, exitCode, cont, runnerErr, err = runLuaRunner(currentRunner, input)
|
||||
input, exitCode, cont, err = runLuaRunner(currentRunner, input)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
cmdFinish(124, input, priv)
|
||||
return
|
||||
}
|
||||
// yep, we only use `err` to check for lua eval error
|
||||
// our actual error should only be a runner provided error at this point
|
||||
// command not found type, etc
|
||||
err = runnerErr
|
||||
}
|
||||
|
||||
if cont {
|
||||
|
@ -162,11 +157,11 @@ func reprompt(input string) (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func runLuaRunner(runr rt.Value, userInput string) (input string, exitCode uint8, continued bool, runnerErr, err error) {
|
||||
func runLuaRunner(runr rt.Value, userInput string) (input string, exitCode uint8, continued bool, err error) {
|
||||
term := rt.NewTerminationWith(l.MainThread().CurrentCont(), 3, false)
|
||||
err = rt.Call(l.MainThread(), runr, []rt.Value{rt.StringValue(userInput)}, term)
|
||||
if err != nil {
|
||||
return "", 124, false, nil, err
|
||||
return
|
||||
}
|
||||
|
||||
var runner *rt.Table
|
||||
|
@ -185,7 +180,7 @@ func runLuaRunner(runr rt.Value, userInput string) (input string, exitCode uint8
|
|||
}
|
||||
|
||||
if errStr, ok := runner.Get(rt.StringValue("err")).TryString(); ok {
|
||||
runnerErr = fmt.Errorf("%s", errStr)
|
||||
err = fmt.Errorf("%s", errStr)
|
||||
}
|
||||
|
||||
if c, ok := runner.Get(rt.StringValue("continue")).TryBool(); ok {
|
||||
|
|
|
@ -24,14 +24,9 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
|
|||
"stat": util.LuaExport{fstat, 1, false},
|
||||
"readdir": util.LuaExport{freaddir, 1, false},
|
||||
"abs": util.LuaExport{fabs, 1, false},
|
||||
"basename": util.LuaExport{fbasename, 1, false},
|
||||
"dir": util.LuaExport{fdir, 1, false},
|
||||
"glob": util.LuaExport{fglob, 1, false},
|
||||
}
|
||||
mod := rt.NewTable()
|
||||
util.SetExports(rtm, mod, exports)
|
||||
mod.Set(rt.StringValue("pathSep"), rt.StringValue(string(os.PathSeparator)))
|
||||
mod.Set(rt.StringValue("pathListSep"), rt.StringValue(string(os.PathListSeparator)))
|
||||
|
||||
util.Document(mod, `The fs module provides easy and simple access to
|
||||
filesystem functions and other things, and acts an
|
||||
|
@ -160,59 +155,3 @@ func fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|||
|
||||
return c.PushingNext1(t.Runtime, rt.StringValue(abspath)), nil
|
||||
}
|
||||
|
||||
// basename(path)
|
||||
// Gives the basename of `path`. For the rules,
|
||||
// see Go's filepath.Base
|
||||
func fbasename(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
if err := c.Check1Arg(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
path, err := c.StringArg(0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.PushingNext(t.Runtime, rt.StringValue(filepath.Base(path))), nil
|
||||
}
|
||||
|
||||
// dir(path)
|
||||
// Returns the directory part of `path`. For the rules, see Go's
|
||||
// filepath.Dir
|
||||
func fdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
if err := c.Check1Arg(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
path, err := c.StringArg(0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.PushingNext(t.Runtime, rt.StringValue(filepath.Dir(path))), nil
|
||||
}
|
||||
|
||||
// glob(pattern)
|
||||
// Glob all files and directories that match the pattern.
|
||||
// For the rules, see Go's filepath.Glob
|
||||
func fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
if err := c.Check1Arg(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pattern, err := c.StringArg(0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
matches, err := filepath.Glob(pattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
luaMatches := rt.NewTable()
|
||||
|
||||
for i, match := range matches {
|
||||
luaMatches.Set(rt.IntValue(int64(i + 1)), rt.StringValue(match))
|
||||
}
|
||||
|
||||
return c.PushingNext(t.Runtime, rt.TableValue(luaMatches)), nil
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
-- Prelude initializes everything else for our shell
|
||||
local _ = require 'succulent' -- Function additions
|
||||
local fs = require 'fs'
|
||||
|
||||
package.path = package.path .. ';' .. hilbish.dataDir .. '/?/init.lua'
|
||||
.. ';' .. hilbish.dataDir .. '/?/?.lua' .. ";" .. hilbish.dataDir .. '/?.lua'
|
||||
|
@ -46,20 +45,3 @@ do
|
|||
})
|
||||
end
|
||||
|
||||
do
|
||||
local startSearchPath = hilbish.userDir.data .. '/hilbish/start/?/init.lua;'
|
||||
.. hilbish.userDir.data .. '/hilbish/start/?.lua'
|
||||
|
||||
local ok, modules = pcall(fs.readdir, hilbish.userDir.data .. '/hilbish/start/')
|
||||
if ok then
|
||||
for _, module in ipairs(modules) do
|
||||
local entry = package.searchpath(module, startSearchPath)
|
||||
print(entry)
|
||||
if entry then
|
||||
dofile(entry)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
package.path = package.path .. ';' .. startSearchPath
|
||||
end
|
||||
|
|
|
@ -55,10 +55,7 @@ func (rl *Instance) Readline() (string, error) {
|
|||
// Multisplit
|
||||
if len(rl.multisplit) > 0 {
|
||||
r := []rune(rl.multisplit[0])
|
||||
if len(r) >= 1 {
|
||||
rl.editorInput(r)
|
||||
}
|
||||
|
||||
rl.editorInput(r)
|
||||
rl.carridgeReturn()
|
||||
if len(rl.multisplit) > 1 {
|
||||
rl.multisplit = rl.multisplit[1:]
|
||||
|
|
Loading…
Reference in New Issue