mirror of https://github.com/Hilbis/Hilbish
Compare commits
6 Commits
226605a996
...
587d08773f
Author | SHA1 | Date |
---|---|---|
TorchedSammy | 587d08773f | |
TorchedSammy | 362bb14d7e | |
TorchedSammy | 153a89b188 | |
TorchedSammy | 453ba9f8ad | |
TorchedSammy | 3e807f5235 | |
TorchedSammy | 7e57b3de7d |
|
@ -48,6 +48,15 @@ includes git commit, branch, and (new!!) release name.
|
||||||
foreground and backgrounds a job respectively.
|
foreground and backgrounds a job respectively.
|
||||||
- Friendlier functions to the `hilbish.runner` interface, which also allow
|
- Friendlier functions to the `hilbish.runner` interface, which also allow
|
||||||
having and using multiple runners.
|
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
|
### Changed
|
||||||
- **Breaking Change:** Upgraded to Lua 5.4.
|
- **Breaking Change:** Upgraded to Lua 5.4.
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
abs(path) > Gives an absolute version of `path`.
|
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`
|
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.
|
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`
|
readdir(dir) > Returns a table of files in `dir`
|
||||||
|
|
|
@ -6,10 +6,22 @@ local fs = {}
|
||||||
--- @param path string
|
--- @param path string
|
||||||
function fs.abs(path) end
|
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`
|
--- Changes directory to `dir`
|
||||||
--- @param dir string
|
--- @param dir string
|
||||||
function fs.cd(dir) end
|
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.
|
--- Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
|
||||||
--- @param name string
|
--- @param name string
|
||||||
--- @param recursive boolean
|
--- @param recursive boolean
|
||||||
|
|
13
exec.go
13
exec.go
|
@ -116,12 +116,17 @@ func runInput(input string, priv bool) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// can only be a string or function so
|
// can only be a string or function so
|
||||||
input, exitCode, cont, err = runLuaRunner(currentRunner, input)
|
var runnerErr error
|
||||||
|
input, exitCode, cont, runnerErr, err = runLuaRunner(currentRunner, input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
cmdFinish(124, input, priv)
|
cmdFinish(124, input, priv)
|
||||||
return
|
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 {
|
if cont {
|
||||||
|
@ -157,11 +162,11 @@ func reprompt(input string) (string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runLuaRunner(runr rt.Value, userInput string) (input string, exitCode uint8, continued bool, err error) {
|
func runLuaRunner(runr rt.Value, userInput string) (input string, exitCode uint8, continued bool, runnerErr, err error) {
|
||||||
term := rt.NewTerminationWith(l.MainThread().CurrentCont(), 3, false)
|
term := rt.NewTerminationWith(l.MainThread().CurrentCont(), 3, false)
|
||||||
err = rt.Call(l.MainThread(), runr, []rt.Value{rt.StringValue(userInput)}, term)
|
err = rt.Call(l.MainThread(), runr, []rt.Value{rt.StringValue(userInput)}, term)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return "", 124, false, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var runner *rt.Table
|
var runner *rt.Table
|
||||||
|
@ -180,7 +185,7 @@ func runLuaRunner(runr rt.Value, userInput string) (input string, exitCode uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
if errStr, ok := runner.Get(rt.StringValue("err")).TryString(); ok {
|
if errStr, ok := runner.Get(rt.StringValue("err")).TryString(); ok {
|
||||||
err = fmt.Errorf("%s", errStr)
|
runnerErr = fmt.Errorf("%s", errStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c, ok := runner.Get(rt.StringValue("continue")).TryBool(); ok {
|
if c, ok := runner.Get(rt.StringValue("continue")).TryBool(); ok {
|
||||||
|
|
|
@ -24,9 +24,14 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
|
||||||
"stat": util.LuaExport{fstat, 1, false},
|
"stat": util.LuaExport{fstat, 1, false},
|
||||||
"readdir": util.LuaExport{freaddir, 1, false},
|
"readdir": util.LuaExport{freaddir, 1, false},
|
||||||
"abs": util.LuaExport{fabs, 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()
|
mod := rt.NewTable()
|
||||||
util.SetExports(rtm, mod, exports)
|
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
|
util.Document(mod, `The fs module provides easy and simple access to
|
||||||
filesystem functions and other things, and acts an
|
filesystem functions and other things, and acts an
|
||||||
|
@ -155,3 +160,59 @@ func fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
|
|
||||||
return c.PushingNext1(t.Runtime, rt.StringValue(abspath)), nil
|
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,5 +1,6 @@
|
||||||
-- Prelude initializes everything else for our shell
|
-- Prelude initializes everything else for our shell
|
||||||
local _ = require 'succulent' -- Function additions
|
local _ = require 'succulent' -- Function additions
|
||||||
|
local fs = require 'fs'
|
||||||
|
|
||||||
package.path = package.path .. ';' .. hilbish.dataDir .. '/?/init.lua'
|
package.path = package.path .. ';' .. hilbish.dataDir .. '/?/init.lua'
|
||||||
.. ';' .. hilbish.dataDir .. '/?/?.lua' .. ";" .. hilbish.dataDir .. '/?.lua'
|
.. ';' .. hilbish.dataDir .. '/?/?.lua' .. ";" .. hilbish.dataDir .. '/?.lua'
|
||||||
|
@ -45,3 +46,20 @@ do
|
||||||
})
|
})
|
||||||
end
|
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,7 +55,10 @@ func (rl *Instance) Readline() (string, error) {
|
||||||
// Multisplit
|
// Multisplit
|
||||||
if len(rl.multisplit) > 0 {
|
if len(rl.multisplit) > 0 {
|
||||||
r := []rune(rl.multisplit[0])
|
r := []rune(rl.multisplit[0])
|
||||||
rl.editorInput(r)
|
if len(r) >= 1 {
|
||||||
|
rl.editorInput(r)
|
||||||
|
}
|
||||||
|
|
||||||
rl.carridgeReturn()
|
rl.carridgeReturn()
|
||||||
if len(rl.multisplit) > 1 {
|
if len(rl.multisplit) > 1 {
|
||||||
rl.multisplit = rl.multisplit[1:]
|
rl.multisplit = rl.multisplit[1:]
|
||||||
|
|
Loading…
Reference in New Issue