From ce99209f0da194d371e7a69357c3906d7d2bd8d3 Mon Sep 17 00:00:00 2001 From: sammyette Date: Tue, 16 Apr 2024 12:09:14 -0400 Subject: [PATCH 01/51] chore: update version info --- CHANGELOG.md | 2 +- vars.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b730b2..ddb63b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # 🎀 Changelog -## Unreleased +## [2.2.2] - 2024-04-16 ### Fixed - Do more checks for a TTY - Panic if ENOTTY is thrown from readline diff --git a/vars.go b/vars.go index 9093a88..ddfef93 100644 --- a/vars.go +++ b/vars.go @@ -11,7 +11,7 @@ var ( // Version info var ( - ver = "v2.2.1" + ver = "v2.2.2" releaseName = "Poppy" gitCommit string From 16b39fe157f72984af21f4c1bcb50b4da45b7960 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 19 Apr 2024 07:54:46 -0400 Subject: [PATCH 02/51] fix: call highlighter and hinter from global table (closes #289) --- api.go | 11 ++++++++++- rl.go | 13 ++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/api.go b/api.go index 9470709..b8e62b3 100644 --- a/api.go +++ b/api.go @@ -712,5 +712,14 @@ func hlhinter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { // #example // #param line string func hlhighlighter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { - return c.Next(), nil + if err := c.Check1Arg(); err != nil { + return nil, err + } + + line, err := c.StringArg(0) + if err != nil { + return nil, err + } + + return c.PushingNext1(t.Runtime, rt.StringValue(line)), nil } diff --git a/rl.go b/rl.go index 7d5ed89..231d04b 100644 --- a/rl.go +++ b/rl.go @@ -70,11 +70,8 @@ func newLineReader(prompt string, noHist bool) *lineReader { hooks.Emit("hilbish.vimAction", actionStr, args) } rl.HintText = func(line []rune, pos int) []rune { - if hinter == nil { - return []rune{} - } - - retVal, err := rt.Call1(l.MainThread(), rt.FunctionValue(hinter), + hinter := hshMod.Get(rt.StringValue("hinter")) + retVal, err := rt.Call1(l.MainThread(), hinter, rt.StringValue(string(line)), rt.IntValue(int64(pos))) if err != nil { fmt.Println(err) @@ -89,10 +86,8 @@ func newLineReader(prompt string, noHist bool) *lineReader { return []rune(hintText) } rl.SyntaxHighlighter = func(line []rune) string { - if highlighter == nil { - return string(line) - } - retVal, err := rt.Call1(l.MainThread(), rt.FunctionValue(highlighter), + highlighter := hshMod.Get(rt.StringValue("highlighter")) + retVal, err := rt.Call1(l.MainThread(), highlighter, rt.StringValue(string(line))) if err != nil { fmt.Println(err) From aa376f9b14135ff2679705d6d47d4a96ea32d742 Mon Sep 17 00:00:00 2001 From: James Dugan <43224155+jdugan6240@users.noreply.github.com> Date: Sat, 20 Apr 2024 17:04:24 -0600 Subject: [PATCH 03/51] feat: cat implementation now uses chunk reading (#290) --- CHANGELOG.md | 7 +++++++ nature/commands/cat.lua | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b52101a..4401297 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # 🎀 Changelog +## Unreleased +### Fixed +- `cat` command no longer prints extra newline at end of each file + +### Added +- `cat` command now reads files in chunks, allowing for reading large files + ## [2.2.2] - 2024-04-16 ### Fixed - Line refresh fixes (less flicker) diff --git a/nature/commands/cat.lua b/nature/commands/cat.lua index 06df507..a2375e9 100644 --- a/nature/commands/cat.lua +++ b/nature/commands/cat.lua @@ -9,6 +9,8 @@ commander.register('cat', function(args, sinks) usage: cat [file]...]] end + local chunkSize = 2^13 -- 8K buffer size + for _, fName in ipairs(args) do local f = io.open(fName) if f == nil then @@ -17,7 +19,11 @@ usage: cat [file]...]] goto continue end - sinks.out:writeln(f:read '*a') + while true do + local block = f:read(chunkSize) + if not block then break end + sinks.out:write(block) + end ::continue:: end io.flush() From f8a391e24fc4c501af164b864f94f9984fcd0148 Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 27 Apr 2024 10:49:26 -0400 Subject: [PATCH 04/51] chore: bump version --- vars.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars.go b/vars.go index ddfef93..1be257c 100644 --- a/vars.go +++ b/vars.go @@ -11,7 +11,7 @@ var ( // Version info var ( - ver = "v2.2.2" + ver = "v2.2.3" releaseName = "Poppy" gitCommit string From 521298733eace72db80cfc9d54ea946237018495 Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 27 Apr 2024 10:52:00 -0400 Subject: [PATCH 05/51] chore: update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4401297..2253549 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # 🎀 Changelog -## Unreleased +## [2.2.3] - 2024-04-27 ### Fixed +- Highligher and hinter work now, since it was regressed from the previous minor release. - `cat` command no longer prints extra newline at end of each file ### Added From fb9d30520ad2678ccf2e4003335616c6afa041d4 Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 27 Apr 2024 13:52:07 -0400 Subject: [PATCH 06/51] fix(greenhouse): draws/updates after exit by resize --- nature/greenhouse/init.lua | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/nature/greenhouse/init.lua b/nature/greenhouse/init.lua index 50d5fad..e58faf7 100644 --- a/nature/greenhouse/init.lua +++ b/nature/greenhouse/init.lua @@ -271,6 +271,15 @@ end function Greenhouse:input(char) end +local function read() + terminal.saveState() + terminal.setRaw() + local c = hilbish.editor.readChar() + + terminal.restoreState() + return c +end + function Greenhouse:initUi() local ansikit = require 'ansikit' local bait = require 'bait' @@ -280,14 +289,17 @@ function Greenhouse:initUi() local Page = require 'nature.greenhouse.page' local done = false - bait.catch('signal.sigint', function() + local function sigint() ansikit.clear() done = true - end) + end - bait.catch('signal.resize', function() + local function resize() self:update() - end) + end + bait.catch('signal.sigint', sigint) + + bait.catch('signal.resize', resize) ansikit.screenAlt() ansikit.clear(true) @@ -311,15 +323,10 @@ function Greenhouse:initUi() ansikit.showCursor() ansikit.screenMain() -end -function read() - terminal.saveState() - terminal.setRaw() - local c = hilbish.editor.readChar() - - terminal.restoreState() - return c + self = nil + bait.release('signal.sigint', sigint) + bait.release('signal.resize', resize) end return Greenhouse From a20123fc24bf5f0ab94fdf4dd1eaff182a04278e Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 27 Apr 2024 21:03:54 -0400 Subject: [PATCH 07/51] feat: allow hilbish.run to take a table of files to use for output (#291) --- CHANGELOG.md | 29 +++++++++ api.go | 118 ++++++++++++++++++++++++++++++---- cmd/docgen/docgen.go | 6 +- docs/api/commander.md | 7 +- docs/api/fs.md | 17 +++++ docs/api/hilbish/_index.md | 13 ++-- emmyLuaDocs/fs.lua | 4 ++ emmyLuaDocs/hilbish.lua | 7 +- exec.go | 40 ++++++++---- go.mod | 24 +++---- go.sum | 51 ++++++--------- golibs/commander/commander.go | 7 +- golibs/fs/fs.go | 18 ++++++ 13 files changed, 261 insertions(+), 80 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2253549..021edf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,33 @@ # 🎀 Changelog +## Unreleased +### Added +- `fs.pipe` function to get a pair of connected files (a pipe). +- Added an alternative 2nd parameter to `hilbish.run`, which is `streams`. +`streams` is a table of input and output streams to run the command with. +It uses these 3 keys: + - `input` as standard input for the command + - `out` as standard output + - `err` as standard error + +Here is a minimal example of the new usage which allows users to now pipe commands +directly via Lua functions: + +```lua +local fs = require 'fs' +local pr, pw = fs.pipe() +hilbish.run('ls -l', { + stdout = pw, + stderr = pw, +}) + +pw:close() + +hilbish.run('wc -l', { + stdin = pr +}) +``` + ## [2.2.3] - 2024-04-27 ### Fixed - Highligher and hinter work now, since it was regressed from the previous minor release. @@ -716,6 +744,7 @@ This input for example will prompt for more input to complete: First "stable" release of Hilbish. +[2.2.3]: https://github.com/Rosettea/Hilbish/compare/v2.2.2...v2.2.3 [2.2.2]: https://github.com/Rosettea/Hilbish/compare/v2.2.1...v2.2.2 [2.2.1]: https://github.com/Rosettea/Hilbish/compare/v2.2.0...v2.2.1 [2.2.0]: https://github.com/Rosettea/Hilbish/compare/v2.1.0...v2.2.0 diff --git a/api.go b/api.go index b8e62b3..6f8f517 100644 --- a/api.go +++ b/api.go @@ -16,6 +16,7 @@ import ( "bytes" "errors" "fmt" + "io" "os" "os/exec" "runtime" @@ -27,6 +28,7 @@ import ( rt "github.com/arnodel/golua/runtime" "github.com/arnodel/golua/lib/packagelib" + "github.com/arnodel/golua/lib/iolib" "github.com/maxlandon/readline" "mvdan.cc/sh/v3/interp" ) @@ -152,12 +154,64 @@ func unsetVimMode() { util.SetField(l, hshMod, "vimMode", rt.NilValue) } -// run(cmd, returnOut) -> exitCode (number), stdout (string), stderr (string) +func handleStream(v rt.Value, strms *streams, errStream bool) error { + ud, ok := v.TryUserData() + if !ok { + return errors.New("expected metatable argument") + } + + val := ud.Value() + var varstrm io.Writer + if f, ok := val.(*iolib.File); ok { + varstrm = f.Handle() + } + + if f, ok := val.(*sink); ok { + varstrm = f.writer + } + + if varstrm == nil { + return errors.New("expected either a sink or file") + } + + if errStream { + strms.stderr = varstrm + } else { + strms.stdout = varstrm + } + + return nil +} + +// run(cmd, streams) -> exitCode (number), stdout (string), stderr (string) // 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. +// As a table, the caller can directly specify the standard output, error, and input +// streams of the command with the table keys `out`, `err`, and `input` respectively. +// As a boolean, it specifies whether the command should use standard output or return its output streams. // #param cmd string -// #param returnOut boolean If this is true, the function will return the standard output and error of the command instead of printing it. +// #param streams table|boolean // #returns number, string, string +// #example +/* +// This code is the same as `ls -l | wc -l` +local fs = require 'fs' +local pr, pw = fs.pipe() +hilbish.run('ls -l', { + stdout = pw, + stderr = pw, +}) + +pw:close() + +hilbish.run('wc -l', { + stdin = pr +}) +*/ +// #example func hlrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { + // TODO: ON BREAKING RELEASE, DO NOT ACCEPT `streams` AS A BOOLEAN. if err := c.Check1Arg(); err != nil { return nil, err } @@ -166,20 +220,57 @@ func hlrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return nil, err } + strms := &streams{} var terminalOut bool if len(c.Etc()) != 0 { tout := c.Etc()[0] - termOut, ok := tout.TryBool() - terminalOut = termOut + + var ok bool + terminalOut, ok = tout.TryBool() if !ok { - return nil, errors.New("bad argument to run (expected boolean, got " + tout.TypeName() + ")") + luastreams, ok := tout.TryTable() + if !ok { + return nil, errors.New("bad argument to run (expected boolean or table, got " + tout.TypeName() + ")") + } + + handleStream(luastreams.Get(rt.StringValue("out")), strms, false) + handleStream(luastreams.Get(rt.StringValue("err")), strms, true) + + stdinstrm := luastreams.Get(rt.StringValue("input")) + if !stdinstrm.IsNil() { + ud, ok := stdinstrm.TryUserData() + if !ok { + return nil, errors.New("bad type as run stdin stream (expected userdata as either sink or file, got " + stdinstrm.TypeName() + ")") + } + + val := ud.Value() + var varstrm io.Reader + if f, ok := val.(*iolib.File); ok { + varstrm = f.Handle() + } + + if f, ok := val.(*sink); ok { + varstrm = f.reader + } + + if varstrm == nil { + return nil, errors.New("bad type as run stdin stream (expected userdata as either sink or file)") + } + + strms.stdin = varstrm + } + } else { + if !terminalOut { + strms = &streams{ + stdout: new(bytes.Buffer), + stderr: new(bytes.Buffer), + } + } } - } else { - terminalOut = true } var exitcode uint8 - stdout, stderr, err := execCommand(cmd, terminalOut) + stdout, stderr, err := execCommand(cmd, strms) if code, ok := interp.IsExitStatus(err); ok { exitcode = code @@ -187,11 +278,12 @@ func hlrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { exitcode = 1 } - stdoutStr := "" - stderrStr := "" - if !terminalOut { - stdoutStr = stdout.(*bytes.Buffer).String() - stderrStr = stderr.(*bytes.Buffer).String() + var stdoutStr, stderrStr string + if stdoutBuf, ok := stdout.(*bytes.Buffer); ok { + stdoutStr = stdoutBuf.String() + } + if stderrBuf, ok := stderr.(*bytes.Buffer); ok { + stderrStr = stderrBuf.String() } return c.PushingNext(t.Runtime, rt.IntValue(int64(exitcode)), rt.StringValue(stdoutStr), rt.StringValue(stderrStr)), nil diff --git a/cmd/docgen/docgen.go b/cmd/docgen/docgen.go index 86a622a..bf8fd1b 100644 --- a/cmd/docgen/docgen.go +++ b/cmd/docgen/docgen.go @@ -488,7 +488,11 @@ func main() { } mdTable.SetContent(i - diff, 0, fmt.Sprintf(`%s`, dps.FuncName, dps.FuncSig)) - mdTable.SetContent(i - diff, 1, dps.Doc[0]) + if len(dps.Doc) == 0 { + fmt.Printf("WARNING! Function %s on module %s has no documentation!\n", dps.FuncName, modname) + } else { + mdTable.SetContent(i - diff, 1, dps.Doc[0]) + } } f.WriteString(mdTable.String()) f.WriteString("\n") diff --git a/docs/api/commander.md b/docs/api/commander.md index 03ece54..c26445a 100644 --- a/docs/api/commander.md +++ b/docs/api/commander.md @@ -26,8 +26,11 @@ In this example, a command with the name of `hello` is created that will print `Hello world!` to output. One question you may have is: What is the `sinks` parameter? -The `sinks` parameter is a table with 3 keys: `in`, `out`, -and `err`. All of them are a Sink. +The `sinks` parameter is a table with 3 keys: `input`, `out`, and `err`. +There is an `in` alias to `input`, but it requires using the string accessor syntax (`sinks['in']`) +as `in` is also a Lua keyword, so `input` is preferred for use. +All of them are a Sink. +In the future, `sinks.in` will be removed. - `in` is the standard input. You may use the read functions on this sink to get input from the user. diff --git a/docs/api/fs.md b/docs/api/fs.md index bc14055..7b733ef 100644 --- a/docs/api/fs.md +++ b/docs/api/fs.md @@ -23,6 +23,7 @@ library offers more functions and will work on any operating system Hilbish does |glob(pattern) -> matches (table)|Match all files based on the provided `pattern`.| |join(...path) -> string|Takes any list of paths and joins them based on the operating system's path separator.| |mkdir(name, recursive)|Creates a new directory with the provided `name`.| +|fpipe() -> File, File|Returns a pair of connected files, also known as a pipe.| |readdir(path) -> table[string]|Returns a list of all files and directories in the provided path.| |stat(path) -> {}|Returns the information about a given `path`.| @@ -183,6 +184,22 @@ fs.mkdir('./foo/bar', true) ``` +
+
+

+fs.fpipe() -> File, File + + + +

+ +Returns a pair of connected files, also known as a pipe. +The type returned is a Lua file, same as returned from `io` functions. + +#### Parameters +This function has no parameters. +
+

diff --git a/docs/api/hilbish/_index.md b/docs/api/hilbish/_index.md index b79dcde..1407e69 100644 --- a/docs/api/hilbish/_index.md +++ b/docs/api/hilbish/_index.md @@ -28,7 +28,7 @@ interfaces and functions which directly relate to shell functionality. |prependPath(dir)|Prepends `dir` to $PATH.| |prompt(str, typ)|Changes the shell prompt to the provided string.| |read(prompt) -> input (string)|Read input from the user, using Hilbish's line editor/input reader.| -|run(cmd, returnOut) -> exitCode (number), stdout (string), stderr (string)|Runs `cmd` in Hilbish's shell script interpreter.| +|run(cmd, streams) -> exitCode (number), stdout (string), stderr (string)|Runs `cmd` in Hilbish's shell script interpreter.| |runnerMode(mode)|Sets the execution/runner mode for interactive Hilbish.| |timeout(cb, time) -> @Timer|Executed the `cb` function after a period of `time`.| |which(name) -> string|Checks if `name` is a valid command.| @@ -413,20 +413,25 @@ Text to print before input, can be empty.

-hilbish.run(cmd, returnOut) -> exitCode (number), stdout (string), stderr (string) +hilbish.run(cmd, streams) -> exitCode (number), stdout (string), stderr (string)

Runs `cmd` in Hilbish's shell script interpreter. +Specifies the output and input streams the command should use. +For example, to write command output to a sink. +As a table, the caller can directly specify the standard output, error, and input +streams of the command with the table keys `out`, `err`, and `input` respectively. +As a boolean, it specifies whether the command should use standard output or return its output streams. #### Parameters `string` **`cmd`** -`boolean` **`returnOut`** -If this is true, the function will return the standard output and error of the command instead of printing it. +`table|boolean` **`streams`** +
diff --git a/emmyLuaDocs/fs.lua b/emmyLuaDocs/fs.lua index 89a418b..ef80eba 100644 --- a/emmyLuaDocs/fs.lua +++ b/emmyLuaDocs/fs.lua @@ -34,6 +34,10 @@ function fs.join(...path) end --- function fs.mkdir(name, recursive) end +--- Returns a pair of connected files, also known as a pipe. +--- The type returned is a Lua file, same as returned from `io` functions. +function fs.fpipe() end + --- Returns a list of all files and directories in the provided path. function fs.readdir(path) end diff --git a/emmyLuaDocs/hilbish.lua b/emmyLuaDocs/hilbish.lua index 7cca355..d931918 100644 --- a/emmyLuaDocs/hilbish.lua +++ b/emmyLuaDocs/hilbish.lua @@ -132,7 +132,12 @@ function hilbish.prompt(str, typ) end function hilbish.read(prompt) end --- Runs `cmd` in Hilbish's shell script interpreter. -function hilbish.run(cmd, returnOut) end +--- Specifies the output and input streams the command should use. +--- For example, to write command output to a sink. +--- As a table, the caller can directly specify the standard output, error, and input +--- streams of the command with the table keys `out`, `err`, and `input` respectively. +--- As a boolean, it specifies whether the command should use standard output or return its output streams. +function hilbish.run(cmd, streams) end --- Sets the execution/runner mode for interactive Hilbish. --- This determines whether Hilbish wll try to run input as Lua diff --git a/exec.go b/exec.go index cf84231..355fa3d 100644 --- a/exec.go +++ b/exec.go @@ -28,6 +28,12 @@ var errNotExec = errors.New("not executable") var errNotFound = errors.New("not found") var runnerMode rt.Value = rt.StringValue("hybrid") +type streams struct { + stdout io.Writer + stderr io.Writer + stdin io.Reader +} + type execError struct{ typ string cmd string @@ -236,7 +242,7 @@ func handleSh(cmdString string) (input string, exitCode uint8, cont bool, runErr } func execSh(cmdString string) (string, uint8, bool, error) { - _, _, err := execCommand(cmdString, true) + _, _, err := execCommand(cmdString, nil) if err != nil { // If input is incomplete, start multiline prompting if syntax.IsIncomplete(err) { @@ -257,7 +263,7 @@ func execSh(cmdString string) (string, uint8, bool, error) { } // Run command in sh interpreter -func execCommand(cmd string, terminalOut bool) (io.Writer, io.Writer, error) { +func execCommand(cmd string, strms *streams) (io.Writer, io.Writer, error) { file, err := syntax.NewParser().Parse(strings.NewReader(cmd), "") if err != nil { return nil, nil, err @@ -265,15 +271,24 @@ func execCommand(cmd string, terminalOut bool) (io.Writer, io.Writer, error) { runner, _ := interp.New() - var stdout io.Writer - var stderr io.Writer - if terminalOut { - interp.StdIO(os.Stdin, os.Stdout, os.Stderr)(runner) - } else { - stdout = new(bytes.Buffer) - stderr = new(bytes.Buffer) - interp.StdIO(os.Stdin, stdout, stderr)(runner) + if strms == nil { + strms = &streams{} } + + if strms.stdout == nil { + strms.stdout = os.Stdout + } + + if strms.stderr == nil { + strms.stderr = os.Stderr + } + + if strms.stdin == nil { + strms.stdin = os.Stdin + } + + interp.StdIO(strms.stdin, strms.stdout, strms.stderr)(runner) + buf := new(bytes.Buffer) printer := syntax.NewPrinter() @@ -292,11 +307,11 @@ func execCommand(cmd string, terminalOut bool) (io.Writer, io.Writer, error) { interp.ExecHandler(execHandle(bg))(runner) err = runner.Run(context.TODO(), stmt) if err != nil { - return stdout, stderr, err + return strms.stdout, strms.stderr, err } } - return stdout, stderr, nil + return strms.stdout, strms.stderr, nil } func execHandle(bg bool) interp.ExecHandlerFunc { @@ -334,6 +349,7 @@ func execHandle(bg bool) interp.ExecHandlerFunc { sinks := rt.NewTable() sinks.Set(rt.StringValue("in"), rt.UserDataValue(stdin.ud)) + sinks.Set(rt.StringValue("input"), rt.UserDataValue(stdin.ud)) sinks.Set(rt.StringValue("out"), rt.UserDataValue(stdout.ud)) sinks.Set(rt.StringValue("err"), rt.UserDataValue(stderr.ud)) diff --git a/go.mod b/go.mod index 6753a17..a7975b7 100644 --- a/go.mod +++ b/go.mod @@ -3,26 +3,26 @@ module hilbish go 1.18 require ( - github.com/arnodel/golua v0.0.0-20220221163911-dfcf252b6f86 + github.com/arnodel/golua v0.0.0-20230215163904-e0b5347eaaa1 github.com/atsushinee/go-markdown-generator v0.0.0-20191121114853-83f9e1f68504 - github.com/blackfireio/osinfo v1.0.3 - github.com/maxlandon/readline v0.1.0-beta.0.20211027085530-2b76cabb8036 + github.com/blackfireio/osinfo v1.0.5 + github.com/maxlandon/readline v1.0.14 github.com/pborman/getopt v1.1.0 - github.com/sahilm/fuzzy v0.1.0 - golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a - golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 - mvdan.cc/sh/v3 v3.5.1 + github.com/sahilm/fuzzy v0.1.1 + golang.org/x/sys v0.19.0 + golang.org/x/term v0.19.0 + mvdan.cc/sh/v3 v3.8.0 ) require ( github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect github.com/arnodel/strftime v0.1.6 // indirect - github.com/evilsocket/islazy v1.10.6 // indirect + github.com/evilsocket/islazy v1.11.0 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0 // indirect - github.com/rivo/uniseg v0.2.0 // indirect - golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect - golang.org/x/text v0.3.7 // indirect + github.com/rivo/uniseg v0.4.7 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/text v0.14.0 // indirect ) replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20220524215627-dfd9a4fa219b @@ -31,4 +31,4 @@ replace github.com/maxlandon/readline => ./readline replace layeh.com/gopher-luar => github.com/layeh/gopher-luar v1.0.10 -replace github.com/arnodel/golua => github.com/Rosettea/golua v0.0.0-20221213193027-cbf6d4e4d345 +replace github.com/arnodel/golua => github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749 diff --git a/go.sum b/go.sum index f82ef01..193f17e 100644 --- a/go.sum +++ b/go.sum @@ -1,26 +1,21 @@ -github.com/Rosettea/golua v0.0.0-20221213193027-cbf6d4e4d345 h1:QNYjYDogUSiNUkffbhFSrSCtpZhofeiVYGFN2FI4wSs= -github.com/Rosettea/golua v0.0.0-20221213193027-cbf6d4e4d345/go.mod h1:9jzpYPiU2is0HVGCiuIOBSXdergHUW44IEjmuN1UrIE= +github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749 h1:jIFnWBTsYw8s7RX7H2AOXjDVhWP3ol7OzUVaPN2KnGI= +github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749/go.mod h1:9jzpYPiU2is0HVGCiuIOBSXdergHUW44IEjmuN1UrIE= github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20220524215627-dfd9a4fa219b h1:s5eDMhBk6H1BgipgLub/gv9qeyBaTuiHM0k3h2/9TSE= github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20220524215627-dfd9a4fa219b/go.mod h1:R09vh/04ILvP2Gj8/Z9Jd0Dh0ZIvaucowMEs6abQpWs= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo= -github.com/arnodel/edit v0.0.0-20220202110212-dfc8d7a13890/go.mod h1:AcpttpuZBaL9xl8/CX+Em4fBTUbwIkJ66RiAsJlNrBk= github.com/arnodel/strftime v0.1.6 h1:0hc0pUvk8KhEMXE+htyaOUV42zNcf/csIbjzEFCJqsw= github.com/arnodel/strftime v0.1.6/go.mod h1:5NbK5XqYK8QpRZpqKNt4OlxLtIB8cotkLk4KTKzJfWs= -github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/atsushinee/go-markdown-generator v0.0.0-20191121114853-83f9e1f68504 h1:R1/AOzdMbopSliUTTEHvHbyNmnZ3YxY5GvdhTkpPsSY= github.com/atsushinee/go-markdown-generator v0.0.0-20191121114853-83f9e1f68504/go.mod h1:kHBCvAXJIatTX1pw6tLiOspjGc3MhUDRlog9yrCUS+k= -github.com/blackfireio/osinfo v1.0.3 h1:Yk2t2GTPjBcESv6nDSWZKO87bGMQgO+Hi9OoXPpxX8c= -github.com/blackfireio/osinfo v1.0.3/go.mod h1:Pd987poVNmd5Wsx6PRPw4+w7kLlf9iJxoRKPtPAjOrA= +github.com/blackfireio/osinfo v1.0.5 h1:6hlaWzfcpb87gRmznVf7wSdhysGqLRz9V/xuSdCEXrA= +github.com/blackfireio/osinfo v1.0.5/go.mod h1:Pd987poVNmd5Wsx6PRPw4+w7kLlf9iJxoRKPtPAjOrA= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.15 h1:cKRCLMj3Ddm54bKSpemfQ8AtYFBhAI2MPmdys22fBdc= github.com/creack/pty v1.1.15/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= -github.com/evilsocket/islazy v1.10.6 h1:MFq000a1ByoumoJWlytqg0qon0KlBeUfPsDjY0hK0bo= -github.com/evilsocket/islazy v1.10.6/go.mod h1:OrwQGYg3DuZvXUfmH+KIZDjwTCbrjy48T24TUpGqVVw= -github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= -github.com/gdamore/tcell/v2 v2.4.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU= +github.com/evilsocket/islazy v1.11.0 h1:B5w6uuS6ki6iDG+aH/RFeoMb8ijQh/pGabewqp2UeJ0= +github.com/evilsocket/islazy v1.11.0/go.mod h1:muYH4x5MB5YRdkxnrOtrXLIBX6LySj1uFIqys94LKdo= github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk= -github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= @@ -30,40 +25,30 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= -github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0 h1:LiZB1h0GIcudcDci2bxbqI6DXV8bF8POAnArqvRrIyw= github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0/go.mod h1:F/7q8/HZz+TXjlsoZQQKVYvXTZaFH4QRa3y+j1p7MS0= github.com/pborman/getopt v1.1.0 h1:eJ3aFZroQqq0bWmraivjQNt6Dmm5M0h2JcDW38/Azb0= github.com/pborman/getopt v1.1.0/go.mod h1:FxXoW1Re00sQG/+KIkuSqRL/LwQgSkv7uyac+STFsbk= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.1-0.20210923151022-86f73c517451 h1:d1PiN4RxzIFXCJTvRkvSkKqwtRAl5ZV4lATKtQI0B7I= github.com/rogpeppe/go-internal v1.8.1-0.20210923151022-86f73c517451/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= -github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI= -github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= +github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA= +github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 h1:w8s32wxx3sY+OjLlv9qltkLU5yvJzxjjgiHWLjdIcw4= -golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210925032602-92d5a993a665/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20210916214954-140adaaadfaf/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 h1:EH1Deb8WZJ0xc0WK//leUHXcX9aLE5SymusoTmMZye8= -golang.org/x/term v0.0.0-20220411215600-e5f449aeb171/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= +golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= mvdan.cc/editorconfig v0.2.0/go.mod h1:lvnnD3BNdBYkhq+B4uBuFFKatfp02eB6HixDvEz91C0= diff --git a/golibs/commander/commander.go b/golibs/commander/commander.go index ea2da7a..f4d588d 100644 --- a/golibs/commander/commander.go +++ b/golibs/commander/commander.go @@ -17,8 +17,11 @@ In this example, a command with the name of `hello` is created that will print `Hello world!` to output. One question you may have is: What is the `sinks` parameter? -The `sinks` parameter is a table with 3 keys: `in`, `out`, -and `err`. All of them are a @Sink. +The `sinks` parameter is a table with 3 keys: `input`, `out`, and `err`. +There is an `in` alias to `input`, but it requires using the string accessor syntax (`sinks['in']`) +as `in` is also a Lua keyword, so `input` is preferred for use. +All of them are a @Sink. +In the future, `sinks.in` will be removed. - `in` is the standard input. You may use the read functions on this sink to get input from the user. diff --git a/golibs/fs/fs.go b/golibs/fs/fs.go index 5bd22c6..9e03325 100644 --- a/golibs/fs/fs.go +++ b/golibs/fs/fs.go @@ -18,6 +18,7 @@ import ( rt "github.com/arnodel/golua/runtime" "github.com/arnodel/golua/lib/packagelib" + "github.com/arnodel/golua/lib/iolib" ) var Loader = packagelib.Loader{ @@ -36,6 +37,7 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) { "dir": util.LuaExport{fdir, 1, false}, "glob": util.LuaExport{fglob, 1, false}, "join": util.LuaExport{fjoin, 0, true}, + "pipe": util.LuaExport{fpipe, 0, false}, } mod := rt.NewTable() util.SetExports(rtm, mod, exports) @@ -226,6 +228,22 @@ func fmkdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return c.Next(), err } +// fpipe() -> File, File +// Returns a pair of connected files, also known as a pipe. +// The type returned is a Lua file, same as returned from `io` functions. +// #returns File +// #returns File +func fpipe(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { + rf, wf, err := os.Pipe() + if err != nil { + return nil, err + } + + rfLua := iolib.NewFile(rf, 0) + wfLua := iolib.NewFile(wf, 0) + + return c.PushingNext(t.Runtime, rfLua.Value(t.Runtime), wfLua.Value(t.Runtime)), nil +} // readdir(path) -> table[string] // Returns a list of all files and directories in the provided path. // #param dir string From 478e3020b11eaca6db9124eac45fc07dbcf00ad7 Mon Sep 17 00:00:00 2001 From: TorchedSammy Date: Sun, 28 Apr 2024 01:04:12 +0000 Subject: [PATCH 08/51] docs: [ci] generate new docs --- docs/api/hilbish/_index.md | 20 +++++++++++++++++++- emmyLuaDocs/hilbish.lua | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/api/hilbish/_index.md b/docs/api/hilbish/_index.md index 1407e69..5c7a0f0 100644 --- a/docs/api/hilbish/_index.md +++ b/docs/api/hilbish/_index.md @@ -420,7 +420,7 @@ hilbish.run(cmd, streams) -> exitCode (number), stdout (string), stderr (string)

Runs `cmd` in Hilbish's shell script interpreter. -Specifies the output and input streams the command should use. +The `streams` parameter specifies the output and input streams the command should use. For example, to write command output to a sink. As a table, the caller can directly specify the standard output, error, and input streams of the command with the table keys `out`, `err`, and `input` respectively. @@ -433,6 +433,24 @@ As a boolean, it specifies whether the command should use standard output or ret `table|boolean` **`streams`** +#### Example +```lua + +// This code is the same as `ls -l | wc -l` +local fs = require 'fs' +local pr, pw = fs.pipe() +hilbish.run('ls -l', { + stdout = pw, + stderr = pw, +}) + +pw:close() + +hilbish.run('wc -l', { + stdin = pr +}) + +```

diff --git a/emmyLuaDocs/hilbish.lua b/emmyLuaDocs/hilbish.lua index d931918..b80a660 100644 --- a/emmyLuaDocs/hilbish.lua +++ b/emmyLuaDocs/hilbish.lua @@ -132,11 +132,12 @@ function hilbish.prompt(str, typ) end function hilbish.read(prompt) end --- Runs `cmd` in Hilbish's shell script interpreter. ---- Specifies the output and input streams the command should use. +--- The `streams` parameter specifies the output and input streams the command should use. --- For example, to write command output to a sink. --- As a table, the caller can directly specify the standard output, error, and input --- streams of the command with the table keys `out`, `err`, and `input` respectively. --- As a boolean, it specifies whether the command should use standard output or return its output streams. +--- function hilbish.run(cmd, streams) end --- Sets the execution/runner mode for interactive Hilbish. From 42ab856e45191c77a26c07bb002983333d750daf Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 27 Apr 2024 21:29:06 -0400 Subject: [PATCH 09/51] feat(commander): add function to return all commanders (closes #266) --- api.go | 2 +- complete.go | 2 +- exec.go | 6 +++--- golibs/commander/commander.go | 27 +++++++++++++++++++++++---- lua.go | 14 +------------- main.go | 3 ++- 6 files changed, 31 insertions(+), 23 deletions(-) diff --git a/api.go b/api.go index 6f8f517..43e361a 100644 --- a/api.go +++ b/api.go @@ -701,7 +701,7 @@ func hlwhich(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { cmd := strings.Split(alias, " ")[0] // check for commander - if commands[cmd] != nil { + if cmds.Commands[cmd] != nil { // they dont resolve to a path, so just send the cmd return c.PushingNext1(t.Runtime, rt.StringValue(cmd)), nil } diff --git a/complete.go b/complete.go index 71d92fb..1c40b20 100644 --- a/complete.go +++ b/complete.go @@ -128,7 +128,7 @@ func binaryComplete(query, ctx string, fields []string) ([]string, string) { } // add lua registered commands to completions - for cmdName := range commands { + for cmdName := range cmds.Commands { if strings.HasPrefix(cmdName, query) { completions = append(completions, cmdName) } diff --git a/exec.go b/exec.go index 355fa3d..cf1b299 100644 --- a/exec.go +++ b/exec.go @@ -342,7 +342,7 @@ func execHandle(bg bool) interp.ExecHandlerFunc { } hc := interp.HandlerCtx(ctx) - if commands[args[0]] != nil { + if cmd := cmds.Commands[args[0]]; cmd != nil { stdin := newSinkInput(hc.Stdin) stdout := newSinkOutput(hc.Stdout) stderr := newSinkOutput(hc.Stderr) @@ -353,7 +353,7 @@ func execHandle(bg bool) interp.ExecHandlerFunc { sinks.Set(rt.StringValue("out"), rt.UserDataValue(stdout.ud)) sinks.Set(rt.StringValue("err"), rt.UserDataValue(stderr.ud)) - luaexitcode, err := rt.Call1(l.MainThread(), rt.FunctionValue(commands[args[0]]), rt.TableValue(luacmdArgs), rt.TableValue(sinks)) + luaexitcode, err := rt.Call1(l.MainThread(), rt.FunctionValue(cmd), rt.TableValue(luacmdArgs), rt.TableValue(sinks)) if err != nil { fmt.Fprintln(os.Stderr, "Error in command:\n" + err.Error()) return interp.NewExitStatus(1) @@ -365,7 +365,7 @@ func execHandle(bg bool) interp.ExecHandlerFunc { exitcode = uint8(code) } else if luaexitcode != rt.NilValue { // deregister commander - delete(commands, args[0]) + delete(cmds.Commands, args[0]) fmt.Fprintf(os.Stderr, "Commander did not return number for exit code. %s, you're fired.\n", args[0]) } diff --git a/golibs/commander/commander.go b/golibs/commander/commander.go index f4d588d..840aaa1 100644 --- a/golibs/commander/commander.go +++ b/golibs/commander/commander.go @@ -43,11 +43,13 @@ import ( type Commander struct{ Events *bait.Bait Loader packagelib.Loader + Commands map[string]*rt.Closure } -func New(rtm *rt.Runtime) Commander { - c := Commander{ +func New(rtm *rt.Runtime) *Commander { + c := &Commander{ Events: bait.New(rtm), + Commands: make(map[string]*rt.Closure), } c.Loader = packagelib.Loader{ Load: c.loaderFunc, @@ -61,6 +63,7 @@ func (c *Commander) loaderFunc(rtm *rt.Runtime) (rt.Value, func()) { exports := map[string]util.LuaExport{ "register": util.LuaExport{c.cregister, 2, false}, "deregister": util.LuaExport{c.cderegister, 1, false}, + "registry": util.LuaExport{c.cregistry, 0, false}, } mod := rt.NewTable() util.SetExports(rtm, mod, exports) @@ -91,7 +94,7 @@ func (c *Commander) cregister(t *rt.Thread, ct *rt.GoCont) (rt.Cont, error) { return nil, err } - c.Events.Emit("commandRegister", cmdName, cmd) + c.Commands[cmdName] = cmd return ct.Next(), err } @@ -108,7 +111,23 @@ func (c *Commander) cderegister(t *rt.Thread, ct *rt.GoCont) (rt.Cont, error) { return nil, err } - c.Events.Emit("commandDeregister", cmdName) + delete(c.Commands, cmdName) return ct.Next(), err } + +// registry() -> table +// Returns all registered commanders. Returns a list of tables with the following keys: +// - `exec`: The function used to run the commander. Commanders require args and sinks to be passed. +// #returns table +func (c *Commander) cregistry(t *rt.Thread, ct *rt.GoCont) (rt.Cont, error) { + registryLua := rt.NewTable() + for cmdName, cmd := range c.Commands { + cmdTbl := rt.NewTable() + cmdTbl.Set(rt.StringValue("exec"), rt.FunctionValue(cmd)) + + registryLua.Set(rt.StringValue(cmdName), rt.TableValue(cmdTbl)) + } + + return ct.PushingNext1(t.Runtime, rt.TableValue(registryLua)), nil +} diff --git a/lua.go b/lua.go index e46d27b..94b7910 100644 --- a/lua.go +++ b/lua.go @@ -33,19 +33,7 @@ func luaInit() { lib.LoadLibs(l, fs.Loader) lib.LoadLibs(l, terminal.Loader) - cmds := commander.New(l) - // When a command from Lua is added, register it for use - cmds.Events.On("commandRegister", func(args ...interface{}) { - cmdName := args[0].(string) - cmd := args[1].(*rt.Closure) - - commands[cmdName] = cmd - }) - cmds.Events.On("commandDeregister", func(args ...interface{}) { - cmdName := args[0].(string) - - delete(commands, cmdName) - }) + cmds = commander.New(l) lib.LoadLibs(l, cmds.Loader) hooks = bait.New(l) diff --git a/main.go b/main.go index 4b756c0..4bdfdac 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( "hilbish/util" "hilbish/golibs/bait" + "hilbish/golibs/commander" rt "github.com/arnodel/golua/runtime" "github.com/pborman/getopt" @@ -25,7 +26,6 @@ var ( l *rt.Runtime lr *lineReader - commands = map[string]*rt.Closure{} luaCompletions = map[string]*rt.Closure{} confDir string @@ -33,6 +33,7 @@ var ( curuser *user.User hooks *bait.Bait + cmds *commander.Commander defaultConfPath string defaultHistPath string ) From d46c079afbaae33d0e28bf3813549aafc38e7b88 Mon Sep 17 00:00:00 2001 From: TorchedSammy Date: Sun, 28 Apr 2024 01:29:33 +0000 Subject: [PATCH 10/51] docs: [ci] generate new docs --- docs/api/commander.md | 17 +++++++++++++++++ emmyLuaDocs/commander.lua | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/docs/api/commander.md b/docs/api/commander.md index c26445a..b910706 100644 --- a/docs/api/commander.md +++ b/docs/api/commander.md @@ -44,6 +44,7 @@ This sink is for writing errors, as the name would suggest. |----|----| |deregister(name)|Removes the named command. Note that this will only remove Commander-registered commands.| |register(name, cb)|Adds a new command with the given `name`. When Hilbish has to run a command with a name,| +|registry() -> table|Returns all registered commanders. Returns a list of tables with the following keys:|
@@ -94,3 +95,19 @@ end) ```
+
+
+

+commander.registry() -> table + + + +

+ +Returns all registered commanders. Returns a list of tables with the following keys: +- `exec`: The function used to run the commander. Commanders require args and sinks to be passed. + +#### Parameters +This function has no parameters. +
+ diff --git a/emmyLuaDocs/commander.lua b/emmyLuaDocs/commander.lua index 285c4b5..bfa69e5 100644 --- a/emmyLuaDocs/commander.lua +++ b/emmyLuaDocs/commander.lua @@ -11,4 +11,8 @@ function commander.deregister(name) end --- function commander.register(name, cb) end +--- Returns all registered commanders. Returns a list of tables with the following keys: +--- - `exec`: The function used to run the commander. Commanders require args and sinks to be passed. +function commander.registry() end + return commander From bbd5637e9bd484ee161aa0930c654478e1d82391 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 3 May 2024 12:47:24 -0400 Subject: [PATCH 11/51] ci: update all actions (#302) --- .github/workflows/build.yml | 16 ++++++++++------ .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/docs.yml | 4 ++-- .github/workflows/release.yml | 4 ++-- .github/workflows/website.yml | 18 +++++++++++------- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4aab838..eeab8a2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,8 +1,12 @@ name: Build on: - - push - - pull_request + push: + branches: + - master + pull_request: + branches: + - master jobs: build: @@ -19,18 +23,18 @@ jobs: goos: windows steps: - name: Checkout sources - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: true - name: Setup Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: '1.18.8' - name: Download Task run: 'sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d' - name: Build run: GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} ./bin/task - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 if: matrix.goos == 'windows' with: name: hilbish-${{ matrix.goos }}-${{ matrix.goarch }} @@ -44,7 +48,7 @@ jobs: libs docs emmyLuaDocs - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 if: matrix.goos != 'windows' with: name: hilbish-${{ matrix.goos }}-${{ matrix.goarch }} diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 9d2728b..453430d 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -26,7 +26,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 6515d25..d524457 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -9,8 +9,8 @@ jobs: gen: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 - name: Run docgen run: go run cmd/docgen/docgen.go - name: Commit new docs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 29d2b83..f4606c3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ jobs: create-release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: taiki-e/create-gh-release-action@v1 with: title: Hilbish $tag @@ -30,7 +30,7 @@ jobs: - goarch: arm64 goos: windows steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true fetch-depth: 0 diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index 88a78ae..4b9b8af 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -1,22 +1,26 @@ name: Build website on: - - push - - pull_request + push: + branches: + - master + pull_request: + branches: + - master jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true fetch-depth: 0 - name: Setup Hugo - uses: peaceiris/actions-hugo@v2 + uses: peaceiris/actions-hugo@v3 with: - hugo-version: 'latest' + hugo-version: '0.111.3' extended: true - name: Set branch name @@ -32,14 +36,14 @@ jobs: - name: Deploy if: env.BRANCH_NAME == 'master' && github.repository_owner == 'Rosettea' - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./website/public keep_files: true - name: Deploy if: env.BRANCH_NAME != 'master' && github.repository_owner == 'Rosettea' - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./website/public From ff6e08902f70ecd234c96f08089fd03464645272 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 3 May 2024 19:06:17 -0400 Subject: [PATCH 12/51] fix(greenhouse): reset at end and beginning of line to fix colors leaking to other lines --- CHANGELOG.md | 3 +++ nature/doc.lua | 4 ++-- nature/greenhouse/init.lua | 45 +++++++++++++++++++++++++++++++++----- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 021edf7..e6eeed8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,9 @@ hilbish.run('wc -l', { }) ``` +### Fixed +- Fix ansi attributes causing issues with text when cut off in greenhouse + ## [2.2.3] - 2024-04-27 ### Fixed - Highligher and hinter work now, since it was regressed from the previous minor release. diff --git a/nature/doc.lua b/nature/doc.lua index 657af51..f0b7e11 100644 --- a/nature/doc.lua +++ b/nature/doc.lua @@ -17,8 +17,8 @@ function M.renderCodeBlock(text) end for i, line in ipairs(lines) do - lines[i] = ' ' .. M.highlight(line:sub(0, longest)) - .. string.rep(' ', longest - line:len()) .. ' ' + lines[i] = lunacolors.format('{greyBg}' .. ' ' .. M.highlight(line:sub(0, longest)) + .. string.rep(' ', longest - line:len()) .. ' ') end return '\n' .. lunacolors.format('{greyBg}' .. table.concat(lines, '\n')) .. '\n' diff --git a/nature/greenhouse/init.lua b/nature/greenhouse/init.lua index e58faf7..fe4c31c 100644 --- a/nature/greenhouse/init.lua +++ b/nature/greenhouse/init.lua @@ -61,17 +61,24 @@ function Greenhouse:updateCurrentPage(text) page:setText(text) end +local ansiPatters = { + '\x1b%[%d+;%d+;%d+;%d+;%d+%w', + '\x1b%[%d+;%d+;%d+;%d+%w', + '\x1b%[%d+;%d+;%d+%w', + '\x1b%[%d+;%d+%w', + '\x1b%[%d+%w' +} + function Greenhouse:sub(str, offset, limit) local overhead = 0 local function addOverhead(s) overhead = overhead + string.len(s) end - local s = str:gsub('\x1b%[%d+;%d+;%d+;%d+;%d+%w', addOverhead) - :gsub('\x1b%[%d+;%d+;%d+;%d+%w', addOverhead) - :gsub('\x1b%[%d+;%d+;%d+%w',addOverhead) - :gsub('\x1b%[%d+;%d+%w', addOverhead) - :gsub('\x1b%[%d+%w', addOverhead) + local s = str + for _, pat in ipairs(ansiPatters) do + s = s:gsub(pat, addOverhead) + end return s:sub(offset, utf8.offset(str, limit + overhead) or limit + overhead) --return s:sub(offset, limit + overhead) @@ -94,14 +101,40 @@ function Greenhouse:draw() self.sink:write(ansikit.getCSI(2, 'J')) local writer = self.sink.writeln + self.attributes = {} for i = offset, offset + self.region.height - 1 do + local resetEnd = false if i > #lines then break end if i == offset + self.region.height - 1 then writer = self.sink.write end self.sink:write(ansikit.getCSI(self.start + i - offset .. ';1', 'H')) local line = lines[i]:gsub('{separator}', function() return self.separator:rep(self.region.width - 1) end) - writer(self.sink, self:sub(line:gsub('\t', ' '), self.horizOffset, self.region.width)) + for _, pat in ipairs(ansiPatters) do + line:gsub(pat, function(s) + if s == lunacolors.formatColors.reset then + self.attributes = {} + resetEnd = true + else + --resetEnd = false + --table.insert(self.attributes, s) + end + end) + end + +--[[ + if #self.attributes ~= 0 then + for _, attr in ipairs(self.attributes) do + --writer(self.sink, attr) + end + end +]]-- + + self.sink:write(lunacolors.formatColors.reset) + writer(self.sink, self:sub(line:gsub('\t', ' '), self.horizOffset, self.region.width + self.horizOffset)) + if resetEnd then + self.sink:write(lunacolors.formatColors.reset) + end end writer(self.sink, '\27[0m') self:render() From 4c61c551aa4a6d2e48cec1232b359f8a7fe5e4fa Mon Sep 17 00:00:00 2001 From: sammyette Date: Mon, 13 May 2024 22:10:28 -0400 Subject: [PATCH 13/51] fix: menu refreshes now there's no flicker *and* its not bugged with leaving the text on exit --- readline/tabfind.go | 2 +- readline/update.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readline/tabfind.go b/readline/tabfind.go index 830dad3..3e46312 100644 --- a/readline/tabfind.go +++ b/readline/tabfind.go @@ -29,7 +29,7 @@ func (rl *Instance) updateTabFind(r []rune) { rl.search = string(rl.tfLine) // We update and print - rl.clearHelpers() + //rl.clearHelpers() rl.getTabCompletion() rl.renderHelpers() } diff --git a/readline/update.go b/readline/update.go index 66b3ba0..0538aad 100644 --- a/readline/update.go +++ b/readline/update.go @@ -121,7 +121,7 @@ func (rl *Instance) clearHelpers() { moveCursorForwards(rl.fullX) // Clear everything below - //print(seqClearScreenBelow) + print(seqClearScreenBelow) // Go back to current cursor position moveCursorBackwards(GetTermWidth()) From 38d036d96fd6760192ec5425f0f5e1d8fcd503eb Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 14 Jun 2024 08:23:12 -0400 Subject: [PATCH 14/51] fix: history navigation going out of bounds --- readline/history.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/readline/history.go b/readline/history.go index e226b4d..0c87a62 100644 --- a/readline/history.go +++ b/readline/history.go @@ -128,15 +128,19 @@ func (rl *Instance) walkHistory(i int) { } rl.histOffset += i + historyLen := history.Len() if rl.histOffset == 0 { rl.line = []rune(rl.lineBuf) rl.pos = len(rl.lineBuf) } else if rl.histOffset <= -1 { rl.histOffset = 0 + } else if rl.histOffset > historyLen { + // TODO: should this wrap around?s + rl.histOffset = 0 } else { dedup = true old = string(rl.line) - new, err = history.GetLine(history.Len() - rl.histOffset) + new, err = history.GetLine(historyLen - rl.histOffset) if err != nil { rl.resetHelpers() print("\r\n" + err.Error() + "\r\n") From 0e4b95d9b9945028b0d957797c2855de070c8033 Mon Sep 17 00:00:00 2001 From: sammyette Date: Tue, 25 Jun 2024 16:48:32 -0400 Subject: [PATCH 15/51] fix: make -S flag set absolute path to hilbish --- main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 4bdfdac..fd511a9 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "os" + "os/exec" "os/user" "path/filepath" "runtime" @@ -115,7 +116,13 @@ func main() { // Set $SHELL if the user wants to if *setshflag { - os.Setenv("SHELL", os.Args[0]) + os.Setenv("SHELL", "hilbish") + + path, err := exec.LookPath("hilbish") + if err == nil { + os.Setenv("SHELL", path) + } + } lr = newLineReader("", false) From b24fc4a422285da3690e6fcb83c3b9043f0a02f0 Mon Sep 17 00:00:00 2001 From: youkwhd <74759624+youkwhd@users.noreply.github.com> Date: Wed, 10 Jul 2024 21:04:15 +0700 Subject: [PATCH 16/51] fix: check if no command passed to exec (#310) * fix: check if no command passed to exec * docs: add exec fixes * chore: remove extra space --- CHANGELOG.md | 1 + nature/commands/exec.lua | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6eeed8..c4db0c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ hilbish.run('wc -l', { ### Fixed - Fix ansi attributes causing issues with text when cut off in greenhouse +- `exec` command should return if no arg presented ## [2.2.3] - 2024-04-27 ### Fixed diff --git a/nature/commands/exec.lua b/nature/commands/exec.lua index d279e31..61ef923 100644 --- a/nature/commands/exec.lua +++ b/nature/commands/exec.lua @@ -1,5 +1,8 @@ local commander = require 'commander' commander.register('exec', function(args) + if #args == 0 then + return + end hilbish.exec(args[1]) end) From d7ab887234d58af0fe2587fcb90332285ea09186 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 19 Jul 2024 09:48:01 -0400 Subject: [PATCH 17/51] feat: allow builds for unix (#311) --- .github/workflows/build.yml | 2 +- execfile_unix.go | 2 +- execfile_windows.go | 2 +- init_windows.go | 2 +- job_unix.go | 2 +- job_windows.go | 2 +- pprof.go | 2 +- signal_unix.go | 2 +- signal_windows.go | 2 +- vars_darwin.go | 2 +- vars_linux.go => vars_unix.go | 2 +- vars_windows.go | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) rename vars_linux.go => vars_unix.go (96%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eeab8a2..f1fe1b1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: '1.18.8' + go-version: '1.22.2' - name: Download Task run: 'sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d' - name: Build diff --git a/execfile_unix.go b/execfile_unix.go index 44f924a..82c738b 100644 --- a/execfile_unix.go +++ b/execfile_unix.go @@ -1,4 +1,4 @@ -// +build linux darwin +//go:build unix package main diff --git a/execfile_windows.go b/execfile_windows.go index 4b3feef..3d6ef61 100644 --- a/execfile_windows.go +++ b/execfile_windows.go @@ -1,4 +1,4 @@ -// +build windows +//go:build windows package main diff --git a/init_windows.go b/init_windows.go index 825069d..e76629b 100644 --- a/init_windows.go +++ b/init_windows.go @@ -1,4 +1,4 @@ -// +build windows +//go:build windows package main diff --git a/job_unix.go b/job_unix.go index 5029012..0a038b1 100644 --- a/job_unix.go +++ b/job_unix.go @@ -1,4 +1,4 @@ -// +build darwin linux +//go:build unix package main diff --git a/job_windows.go b/job_windows.go index 140a5d1..26818b5 100644 --- a/job_windows.go +++ b/job_windows.go @@ -1,4 +1,4 @@ -// +build windows +//go:build windows package main diff --git a/pprof.go b/pprof.go index 977eeb0..ac4ed55 100644 --- a/pprof.go +++ b/pprof.go @@ -1,4 +1,4 @@ -// +build pprof +//go:build pprof package main diff --git a/signal_unix.go b/signal_unix.go index 2e6c885..1564d93 100644 --- a/signal_unix.go +++ b/signal_unix.go @@ -1,4 +1,4 @@ -// +build darwin linux +//go:build unix package main diff --git a/signal_windows.go b/signal_windows.go index 42a9fff..2ed3370 100644 --- a/signal_windows.go +++ b/signal_windows.go @@ -1,4 +1,4 @@ -// +build windows +//go:build windows package main diff --git a/vars_darwin.go b/vars_darwin.go index 8ec83ba..43215d5 100644 --- a/vars_darwin.go +++ b/vars_darwin.go @@ -1,4 +1,4 @@ -// +build darwin +//go:build darwin package main diff --git a/vars_linux.go b/vars_unix.go similarity index 96% rename from vars_linux.go rename to vars_unix.go index e1160ba..f90fa55 100644 --- a/vars_linux.go +++ b/vars_unix.go @@ -1,4 +1,4 @@ -// +build linux +//go:build unix && !darwin package main diff --git a/vars_windows.go b/vars_windows.go index d1bd7b6..f724fc2 100644 --- a/vars_windows.go +++ b/vars_windows.go @@ -1,4 +1,4 @@ -// +build windows +//go:build windows package main From f7e66bb95711c21c2324c6c9c0cbfbc9d2abeda8 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 19 Jul 2024 09:48:40 -0400 Subject: [PATCH 18/51] docs: bump version requirement --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 469630b..9d6446c 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ on the website for distributed binaries from GitHub or other package repositorie Otherwise, continue reading for steps on compiling. ## Prerequisites -- [Go 1.17+](https://go.dev) +- [Go 1.22+](https://go.dev) - [Task](https://taskfile.dev/installation/) (**Go on the hyperlink here to see Task's install method for your OS.**) ## Build From 826b0789cbbc7e4633f9f1d02e89b44a473921e1 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 19 Jul 2024 17:43:49 -0400 Subject: [PATCH 19/51] docs: promote midnight edition on main readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9d6446c..4566c30 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +> [!TIP] +> Check out [Hilbish: Midnight Edition](https://github.com/Rosettea/Hilbish/tree/midnight-edition) if you want to use C Lua, LuaJIT or anything related! +
🌓 The Moon-powered shell! A comfy and extensible shell for Lua fans! 🌺 ✨ From 41e5e3f789b2c3b730e48b1216d80ded6f768f03 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 19 Jul 2024 18:46:46 -0400 Subject: [PATCH 20/51] feat: commanders can exit via ctrl c (#313) --- CHANGELOG.md | 2 ++ exec.go | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4db0c7..dcee77d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ hilbish.run('wc -l', { ### Fixed - Fix ansi attributes causing issues with text when cut off in greenhouse - `exec` command should return if no arg presented +- Commanders can now be cancelled by Ctrl-C and wont hang the shell anymore. +See [issue 198](https://github.com/Rosettea/Hilbish/issues/198). ## [2.2.3] - 2024-04-27 ### Fixed diff --git a/exec.go b/exec.go index cf1b299..5def9aa 100644 --- a/exec.go +++ b/exec.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "os" + "os/signal" "path/filepath" "runtime" "strings" @@ -353,7 +354,34 @@ func execHandle(bg bool) interp.ExecHandlerFunc { sinks.Set(rt.StringValue("out"), rt.UserDataValue(stdout.ud)) sinks.Set(rt.StringValue("err"), rt.UserDataValue(stderr.ud)) - luaexitcode, err := rt.Call1(l.MainThread(), rt.FunctionValue(cmd), rt.TableValue(luacmdArgs), rt.TableValue(sinks)) + t := rt.NewThread(l) + sig := make(chan os.Signal) + exit := make(chan bool) + + luaexitcode := rt.IntValue(63) + var err error + go func() { + defer func() { + if r := recover(); r != nil { + exit <- true + } + }() + + signal.Notify(sig, os.Interrupt) + select { + case <-sig: + t.KillContext() + return + } + + }() + + go func() { + luaexitcode, err = rt.Call1(t, rt.FunctionValue(cmd), rt.TableValue(luacmdArgs), rt.TableValue(sinks)) + exit <- true + }() + + <-exit if err != nil { fmt.Fprintln(os.Stderr, "Error in command:\n" + err.Error()) return interp.NewExitStatus(1) From 5f8d942f0a80863a4190f9cb20db61fd24ba11fd Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 20 Jul 2024 09:31:57 -0400 Subject: [PATCH 21/51] fix: reuse shell runner instance (#312) --- CHANGELOG.md | 1 + exec.go | 2 -- go.mod | 11 +++++---- go.sum | 44 ++++++++++++++--------------------- golibs/fs/fs.go | 62 ++++++++++++++++++++++++++++++------------------- lua.go | 3 ++- main.go | 3 +++ 7 files changed, 69 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcee77d..b97e2a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ hilbish.run('wc -l', { - `exec` command should return if no arg presented - Commanders can now be cancelled by Ctrl-C and wont hang the shell anymore. See [issue 198](https://github.com/Rosettea/Hilbish/issues/198). +- Shell interpreter can now preserve its environment and set PWD properly. ## [2.2.3] - 2024-04-27 ### Fixed diff --git a/exec.go b/exec.go index 5def9aa..446a14d 100644 --- a/exec.go +++ b/exec.go @@ -270,8 +270,6 @@ func execCommand(cmd string, strms *streams) (io.Writer, io.Writer, error) { return nil, nil, err } - runner, _ := interp.New() - if strms == nil { strms = &streams{} } diff --git a/go.mod b/go.mod index a7975b7..985f2e2 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module hilbish -go 1.18 +go 1.21 + +toolchain go1.22.2 require ( github.com/arnodel/golua v0.0.0-20230215163904-e0b5347eaaa1 @@ -9,8 +11,8 @@ require ( github.com/maxlandon/readline v1.0.14 github.com/pborman/getopt v1.1.0 github.com/sahilm/fuzzy v0.1.1 - golang.org/x/sys v0.19.0 - golang.org/x/term v0.19.0 + golang.org/x/sys v0.22.0 + golang.org/x/term v0.22.0 mvdan.cc/sh/v3 v3.8.0 ) @@ -19,13 +21,14 @@ require ( github.com/arnodel/strftime v0.1.6 // indirect github.com/evilsocket/islazy v1.11.0 // indirect github.com/kylelemons/godebug v1.1.0 // indirect + github.com/muesli/cancelreader v0.2.2 // indirect github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0 // indirect github.com/rivo/uniseg v0.4.7 // indirect golang.org/x/sync v0.7.0 // indirect golang.org/x/text v0.14.0 // indirect ) -replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20220524215627-dfd9a4fa219b +replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240720131751-805c301321fd replace github.com/maxlandon/readline => ./readline diff --git a/go.sum b/go.sum index 193f17e..136f827 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749 h1:jIFnWBTsYw8s7RX7H2AOXjDVhWP3ol7OzUVaPN2KnGI= github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749/go.mod h1:9jzpYPiU2is0HVGCiuIOBSXdergHUW44IEjmuN1UrIE= -github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20220524215627-dfd9a4fa219b h1:s5eDMhBk6H1BgipgLub/gv9qeyBaTuiHM0k3h2/9TSE= -github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20220524215627-dfd9a4fa219b/go.mod h1:R09vh/04ILvP2Gj8/Z9Jd0Dh0ZIvaucowMEs6abQpWs= +github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240720131751-805c301321fd h1:THNle0FR2g7DMO1y3Bx1Zr7rYeiLXt3st3UkxEsMzL4= +github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240720131751-805c301321fd/go.mod h1:YZalN5H7WNQw3DGij6IvHsEhn5YMW7M2FCwG6gnfKy4= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo= github.com/arnodel/strftime v0.1.6 h1:0hc0pUvk8KhEMXE+htyaOUV42zNcf/csIbjzEFCJqsw= @@ -10,45 +10,37 @@ github.com/atsushinee/go-markdown-generator v0.0.0-20191121114853-83f9e1f68504 h github.com/atsushinee/go-markdown-generator v0.0.0-20191121114853-83f9e1f68504/go.mod h1:kHBCvAXJIatTX1pw6tLiOspjGc3MhUDRlog9yrCUS+k= github.com/blackfireio/osinfo v1.0.5 h1:6hlaWzfcpb87gRmznVf7wSdhysGqLRz9V/xuSdCEXrA= github.com/blackfireio/osinfo v1.0.5/go.mod h1:Pd987poVNmd5Wsx6PRPw4+w7kLlf9iJxoRKPtPAjOrA= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/creack/pty v1.1.15 h1:cKRCLMj3Ddm54bKSpemfQ8AtYFBhAI2MPmdys22fBdc= -github.com/creack/pty v1.1.15/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= +github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0= +github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/evilsocket/islazy v1.11.0 h1:B5w6uuS6ki6iDG+aH/RFeoMb8ijQh/pGabewqp2UeJ0= github.com/evilsocket/islazy v1.11.0/go.mod h1:muYH4x5MB5YRdkxnrOtrXLIBX6LySj1uFIqys94LKdo= -github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI= +github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= +github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0 h1:LiZB1h0GIcudcDci2bxbqI6DXV8bF8POAnArqvRrIyw= github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0/go.mod h1:F/7q8/HZz+TXjlsoZQQKVYvXTZaFH4QRa3y+j1p7MS0= github.com/pborman/getopt v1.1.0 h1:eJ3aFZroQqq0bWmraivjQNt6Dmm5M0h2JcDW38/Azb0= github.com/pborman/getopt v1.1.0/go.mod h1:FxXoW1Re00sQG/+KIkuSqRL/LwQgSkv7uyac+STFsbk= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.1-0.20210923151022-86f73c517451 h1:d1PiN4RxzIFXCJTvRkvSkKqwtRAl5ZV4lATKtQI0B7I= -github.com/rogpeppe/go-internal v1.8.1-0.20210923151022-86f73c517451/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA= github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210925032602-92d5a993a665/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20210916214954-140adaaadfaf/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= -golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= +golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -mvdan.cc/editorconfig v0.2.0/go.mod h1:lvnnD3BNdBYkhq+B4uBuFFKatfp02eB6HixDvEz91C0= diff --git a/golibs/fs/fs.go b/golibs/fs/fs.go index 9e03325..13f972d 100644 --- a/golibs/fs/fs.go +++ b/golibs/fs/fs.go @@ -19,25 +19,38 @@ import ( rt "github.com/arnodel/golua/runtime" "github.com/arnodel/golua/lib/packagelib" "github.com/arnodel/golua/lib/iolib" + "mvdan.cc/sh/v3/interp" ) -var Loader = packagelib.Loader{ - Load: loaderFunc, - Name: "fs", +type fs struct{ + runner *interp.Runner + Loader packagelib.Loader } -func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) { +func New(runner *interp.Runner) *fs { + f := &fs{ + runner: runner, + } + f.Loader = packagelib.Loader{ + Load: f.loaderFunc, + Name: "fs", + } + + return f +} + +func (f *fs) loaderFunc(rtm *rt.Runtime) (rt.Value, func()) { exports := map[string]util.LuaExport{ - "cd": util.LuaExport{fcd, 1, false}, - "mkdir": util.LuaExport{fmkdir, 2, false}, - "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}, - "join": util.LuaExport{fjoin, 0, true}, - "pipe": util.LuaExport{fpipe, 0, false}, + "cd": util.LuaExport{f.fcd, 1, false}, + "mkdir": util.LuaExport{f.fmkdir, 2, false}, + "stat": util.LuaExport{f.fstat, 1, false}, + "readdir": util.LuaExport{f.freaddir, 1, false}, + "abs": util.LuaExport{f.fabs, 1, false}, + "basename": util.LuaExport{f.fbasename, 1, false}, + "dir": util.LuaExport{f.fdir, 1, false}, + "glob": util.LuaExport{f.fglob, 1, false}, + "join": util.LuaExport{f.fjoin, 0, true}, + "pipe": util.LuaExport{f.fpipe, 0, false}, } mod := rt.NewTable() util.SetExports(rtm, mod, exports) @@ -52,7 +65,7 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) { // This can be used to resolve short paths like `..` to `/home/user`. // #param path string // #returns string -func fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func (f *fs) fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { path, err := c.StringArg(0) if err != nil { return nil, err @@ -72,7 +85,7 @@ func fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { // `.` will be returned. // #param path string Path to get the base name of. // #returns string -func fbasename(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func (f *fs) fbasename(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.Check1Arg(); err != nil { return nil, err } @@ -87,7 +100,7 @@ func fbasename(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { // cd(dir) // Changes Hilbish's directory to `dir`. // #param dir string Path to change directory to. -func fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func (f *fs) fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.Check1Arg(); err != nil { return nil, err } @@ -101,6 +114,7 @@ func fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err != nil { return nil, err } + interp.Dir(path)(f.runner) return c.Next(), err } @@ -110,7 +124,7 @@ func fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { // `~/Documents/doc.txt` then this function will return `~/Documents`. // #param path string Path to get the directory for. // #returns string -func fdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func (f *fs) fdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.Check1Arg(); err != nil { return nil, err } @@ -141,7 +155,7 @@ print(matches) -- -> {'init.lua', 'code.lua'} #example */ -func fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func (f *fs) fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.Check1Arg(); err != nil { return nil, err } @@ -175,7 +189,7 @@ print(fs.join(hilbish.userDir.config, 'hilbish')) -- -> '/home/user/.config/hilbish' on Linux #example */ -func fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func (f *fs) fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { strs := make([]string, len(c.Etc())) for i, v := range c.Etc() { if v.Type() != rt.StringType { @@ -202,7 +216,7 @@ func fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { fs.mkdir('./foo/bar', true) #example */ -func fmkdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func (f *fs) fmkdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.CheckNArgs(2); err != nil { return nil, err } @@ -233,7 +247,7 @@ func fmkdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { // The type returned is a Lua file, same as returned from `io` functions. // #returns File // #returns File -func fpipe(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func (f *fs) fpipe(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { rf, wf, err := os.Pipe() if err != nil { return nil, err @@ -248,7 +262,7 @@ func fpipe(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { // Returns a list of all files and directories in the provided path. // #param dir string // #returns table -func freaddir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func (f *fs) freaddir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.Check1Arg(); err != nil { return nil, err } @@ -296,7 +310,7 @@ Would print the following: ]]-- #example */ -func fstat(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func (f *fs) fstat(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.Check1Arg(); err != nil { return nil, err } diff --git a/lua.go b/lua.go index 94b7910..88fedf8 100644 --- a/lua.go +++ b/lua.go @@ -30,7 +30,8 @@ func luaInit() { util.DoString(l, "hilbish = require 'hilbish'") // Add fs and terminal module module to Lua - lib.LoadLibs(l, fs.Loader) + f := fs.New(runner) + lib.LoadLibs(l, f.Loader) lib.LoadLibs(l, terminal.Loader) cmds = commander.New(l) diff --git a/main.go b/main.go index fd511a9..41d1d35 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ import ( "github.com/pborman/getopt" "github.com/maxlandon/readline" "golang.org/x/term" + "mvdan.cc/sh/v3/interp" ) var ( @@ -37,9 +38,11 @@ var ( cmds *commander.Commander defaultConfPath string defaultHistPath string + runner *interp.Runner ) func main() { + runner, _ = interp.New() curuser, _ = user.Current() homedir := curuser.HomeDir confDir, _ = os.UserConfigDir() From 4e882b376b8d6b9c07a7b837813a55fafb71a700 Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 20 Jul 2024 09:36:42 -0400 Subject: [PATCH 22/51] chore: update version info --- CHANGELOG.md | 3 ++- vars.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b97e2a0..eb95cc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # 🎀 Changelog -## Unreleased +## [2.3.0] - 2024-07-20 ### Added - `fs.pipe` function to get a pair of connected files (a pipe). - Added an alternative 2nd parameter to `hilbish.run`, which is `streams`. @@ -751,6 +751,7 @@ This input for example will prompt for more input to complete: First "stable" release of Hilbish. +[2.3.0]: https://github.com/Rosettea/Hilbish/compare/v2.2.3...v2.3.0 [2.2.3]: https://github.com/Rosettea/Hilbish/compare/v2.2.2...v2.2.3 [2.2.2]: https://github.com/Rosettea/Hilbish/compare/v2.2.1...v2.2.2 [2.2.1]: https://github.com/Rosettea/Hilbish/compare/v2.2.0...v2.2.1 diff --git a/vars.go b/vars.go index 1be257c..bad94db 100644 --- a/vars.go +++ b/vars.go @@ -11,8 +11,8 @@ var ( // Version info var ( - ver = "v2.2.3" - releaseName = "Poppy" + ver = "v2.3.0" + releaseName = "Alyssum" gitCommit string gitBranch string From 92448eec67f3de15813047033fc8b89aa3d22d7f Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 20 Jul 2024 09:57:51 -0400 Subject: [PATCH 23/51] ci: add workflow dispatch to website --- .github/workflows/website.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index 4b9b8af..56da2e6 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -7,6 +7,7 @@ on: pull_request: branches: - master + workflow_dispatch: jobs: deploy: From 44d63a398ad6d49ef53a2230f6717e3e34eec1bc Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 20 Jul 2024 10:03:36 -0400 Subject: [PATCH 24/51] chore: update changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb95cc8..f0f00a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [2.3.0] - 2024-07-20 ### Added +- `commander.registry` function to get all registered commanders. - `fs.pipe` function to get a pair of connected files (a pipe). - Added an alternative 2nd parameter to `hilbish.run`, which is `streams`. `streams` is a table of input and output streams to run the command with. @@ -28,8 +29,14 @@ hilbish.run('wc -l', { }) ``` +### Changed +- The `-S` flag will be set to Hilbish's absolute path +- Hilbish now builds on any Unix (if any dependencies also work, which should.) + ### Fixed - Fix ansi attributes causing issues with text when cut off in greenhouse +- Fix greenhouse appearing on terminal resize +- Fix crashes when history goes out of bounds when using history navigation - `exec` command should return if no arg presented - Commanders can now be cancelled by Ctrl-C and wont hang the shell anymore. See [issue 198](https://github.com/Rosettea/Hilbish/issues/198). From 1ba0dd183c94d41d0e0669ea94bc90070448e8d4 Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 20 Jul 2024 10:14:16 -0400 Subject: [PATCH 25/51] blog: add v2.3 release blog --- website/content/blog/v2.3-release.md | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 website/content/blog/v2.3-release.md diff --git a/website/content/blog/v2.3-release.md b/website/content/blog/v2.3-release.md new file mode 100644 index 0000000..3185148 --- /dev/null +++ b/website/content/blog/v2.3-release.md @@ -0,0 +1,48 @@ +--- +title: "v2.3 Release" +date: 2024-07-20T10:05:17-04:00 +draft: false +--- + + +> The release with full changelogs and prebuilt binaries can be +seen at the [v2.3.0](https://github.com/Rosettea/Hilbish/releases/tag/v2.3.0) +tag. + +Hilbish v2.3 has now been released! This is small feature and bug fix release +which took a while to cme ut since I took a long break from programming in general. +The next release will be great, so stay tuned for that. + +# Features +## Pipes (via Lua) +Commands can now be piped to each other via the Lua API with the `hilbish.run` +function and an `fs.pipe`. + +Here is a minimal example of the new usage which allows users to now pipe commands +directly via Lua functions: + +```lua +local fs = require 'fs' +local pr, pw = fs.pipe() +hilbish.run('ls -l', { + stdout = pw, + stderr = pw, +}) + +pw:close() + +hilbish.run('wc -l', { + stdin = pr +}) +``` + +This also means it's easier to make commands output to any stream output, +including in commanders. + +# Bug Fixes +- Commanders can now be cancelled with Ctrl-C, which means if they froze for some reason +they can now be exited. +- The shell script interpreter now keeps its environment, and this also fixes the +current working directory being wrong with some commands. +- Some greenhouse bugs have been fixed, like randomly appearing when resizing the terminal +and some text attributes like color appearing where they weren't supposed to. From cc43cb2d6eb0b030beacc1646adb67f408dd92e5 Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 20 Jul 2024 10:19:22 -0400 Subject: [PATCH 26/51] fix: make website build on tag pushes --- .github/workflows/website.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index 56da2e6..dba7ca0 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -4,6 +4,8 @@ on: push: branches: - master + tags: + - v[0-9]+.* pull_request: branches: - master From 8a1614ab591aec6b03e6fe0a289aa0fa6723644a Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 20 Jul 2024 10:24:56 -0400 Subject: [PATCH 27/51] ci: use wildcard for refs on branch name --- .github/workflows/website.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index dba7ca0..d5859b8 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -28,7 +28,7 @@ jobs: - name: Set branch name id: branch - run: echo "BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV" + run: echo "BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/*/}}" >> "$GITHUB_ENV" - name: Fix base URL if: env.BRANCH_NAME != 'master' && github.repository_owner == 'Rosettea' From 35a8d0eaa4f59478027201aacbf987fca7e4b7fb Mon Sep 17 00:00:00 2001 From: Nathan J Helmig <62121934+nhlmg93@users.noreply.github.com> Date: Sun, 21 Jul 2024 18:02:46 -0500 Subject: [PATCH 28/51] feat: adds some friendly tips (#315) Co-authored-by: Nathan Helmig --- CHANGELOG.md | 5 +++++ nature/opts/init.lua | 3 ++- nature/opts/tips.lua | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 nature/opts/tips.lua diff --git a/CHANGELOG.md b/CHANGELOG.md index f0f00a0..f130876 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 🎀 Changelog +## Unreleased +### Added +- `nature.opts.tips` was added to randomly generate tips on start up. +Follows the pattern of motd and greeting. Displays after greeting on start up. + ## [2.3.0] - 2024-07-20 ### Added - `commander.registry` function to get all registered commanders. diff --git a/nature/opts/init.lua b/nature/opts/init.lua index 474ea3b..d55864f 100644 --- a/nature/opts/init.lua +++ b/nature/opts/init.lua @@ -14,7 +14,8 @@ The nice lil shell for {blue}Lua{reset} fanatics! motd = true, fuzzy = false, notifyJobFinish = true, - crimmas = true + crimmas = true, + tips = true } for optsName, default in pairs(defaultOpts) do diff --git a/nature/opts/tips.lua b/nature/opts/tips.lua new file mode 100644 index 0000000..d25e105 --- /dev/null +++ b/nature/opts/tips.lua @@ -0,0 +1,34 @@ +local bait = require 'bait' +local lunacolors = require 'lunacolors' + +PREAMBLE = [[ +Getting Started: https://rosettea.github.io/Hilbish/docs/getting-started/ +{yellow}🛈 These tips can be disabled with hilbish.opts.tips = false{reset} +]] + +hilbish.tips = { + "Join the discord and say hi! -> https://discord.gg/3PDdcQz", + "{green}hilbish.alias{reset} -> Sets an alias to another cmd", + "{green}hilbish.appendPath{reset} -> Appends the provided dir to the command path ($PATH)", + "{green}hilbish.completions{reset} -> Are use to control suggestions when tab completing.", + "{green}hilbish.message{reset} -> Simple notification system which can be used by other plugins and parts of the shell to notify the user of various actions.", + [[ + {green}hilbish.opts{reset} -> Simple toggle or value options a user can set. + - EX: hilbish.opts.greeting = false, will cause the greeting message on start-up to not display. + ]], + [[ + {green}hilbish.runner{reset} -> The runner interface contains functions that allow the user to change how Hilbish interprets interactive input. + - The default runners can run shell script and Lua code. + ]], + [[ + Add Lua-written commands with the commander module! + Checkout the docs here -> https://rosettea.github.io/Hilbish/docs/api/commander/ + ]] +} + +bait.catch('hilbish.init', function() + if hilbish.interactive and hilbish.opts.tip then + local idx = math.random(1, #hilbish.tips) + print(lunacolors.format(PREAMBLE .. "\nTip: " .. hilbish.tips[idx])) + end +end) From a41a5504f4fe0d5204f939ce32a0cfc70f068b49 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 26 Jul 2024 18:07:55 -0400 Subject: [PATCH 29/51] fix(nature/tips): opt typo --- nature/opts/tips.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nature/opts/tips.lua b/nature/opts/tips.lua index d25e105..c8b36e3 100644 --- a/nature/opts/tips.lua +++ b/nature/opts/tips.lua @@ -27,7 +27,7 @@ hilbish.tips = { } bait.catch('hilbish.init', function() - if hilbish.interactive and hilbish.opts.tip then + if hilbish.interactive and hilbish.opts.tips then local idx = math.random(1, #hilbish.tips) print(lunacolors.format(PREAMBLE .. "\nTip: " .. hilbish.tips[idx])) end From 5b4615800802b7aef89492a222729d9bf4958081 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 26 Jul 2024 18:08:16 -0400 Subject: [PATCH 30/51] fix(commands/cd): use absolute paths to cd --- nature/commands/cd.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nature/commands/cd.lua b/nature/commands/cd.lua index 7cfe4a2..22078d9 100644 --- a/nature/commands/cd.lua +++ b/nature/commands/cd.lua @@ -19,7 +19,7 @@ commander.register('cd', function (args, sinks) dirs.setOld(hilbish.cwd()) dirs.push(path) - local ok, err = pcall(function() fs.cd(path) end) + local ok, err = pcall(function() fs.cd(fs.abs(path)) end) if not ok then sinks.out:writeln(err) return 1 From ddf5117fd99864f9b2c0a76d84d3220105bad541 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 26 Jul 2024 18:08:43 -0400 Subject: [PATCH 31/51] chore: bump version --- vars.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars.go b/vars.go index bad94db..6b4bba8 100644 --- a/vars.go +++ b/vars.go @@ -11,7 +11,7 @@ var ( // Version info var ( - ver = "v2.3.0" + ver = "v2.3.1" releaseName = "Alyssum" gitCommit string From 54b85b1c99b056345adf2863f5bfe65429cfa82a Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 27 Jul 2024 14:10:21 -0400 Subject: [PATCH 32/51] fix: add 2.3 motd --- nature/opts/motd.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nature/opts/motd.lua b/nature/opts/motd.lua index c1f31b4..6d957d3 100644 --- a/nature/opts/motd.lua +++ b/nature/opts/motd.lua @@ -2,8 +2,9 @@ local bait = require 'bait' local lunacolors = require 'lunacolors' hilbish.motd = [[ -Finally at {red}v2.2!{reset} So much {green}documentation improvements{reset} -and 1 single fix for Windows! {blue}.. and a feature they can't use.{reset} +Wait ... {magenta}2.3{reset} is basically the same as {red}2.2?{reset} +Erm.. {blue}Ctrl-C works for Commanders,{reset} {cyan}and the sh runner has some fixes.{reset} +Just trust me bro, this is an imporant bug fix release. {red}- 🌺 sammyette{reset} ]] bait.catch('hilbish.init', function() From e4df61f020f29c8d5178e5666f99064ecabe23a7 Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 27 Jul 2024 14:19:53 -0400 Subject: [PATCH 33/51] fix(nature/tips): cleanup tips display --- nature/opts/tips.lua | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/nature/opts/tips.lua b/nature/opts/tips.lua index c8b36e3..c951b2e 100644 --- a/nature/opts/tips.lua +++ b/nature/opts/tips.lua @@ -1,34 +1,35 @@ local bait = require 'bait' local lunacolors = require 'lunacolors' -PREAMBLE = [[ -Getting Started: https://rosettea.github.io/Hilbish/docs/getting-started/ -{yellow}🛈 These tips can be disabled with hilbish.opts.tips = false{reset} +local postamble = [[ +{yellow}These tips can be disabled with {reset}{invert} hilbish.opts.tips = false {reset} ]] hilbish.tips = { - "Join the discord and say hi! -> https://discord.gg/3PDdcQz", - "{green}hilbish.alias{reset} -> Sets an alias to another cmd", - "{green}hilbish.appendPath{reset} -> Appends the provided dir to the command path ($PATH)", - "{green}hilbish.completions{reset} -> Are use to control suggestions when tab completing.", - "{green}hilbish.message{reset} -> Simple notification system which can be used by other plugins and parts of the shell to notify the user of various actions.", + 'Join the discord and say hi! {blue}https://discord.gg/3PDdcQz{reset}', + '{green}hilbish.alias{reset} interface manages shell aliases. See more detail by running {blue}doc api hilbish.alias.', + '{green}hilbish.appendPath(\'path\'){reset} -> Appends the provided dir to the command path ($PATH)', + '{green}hilbish.completions{reset} -> Used to control suggestions when tab completing.', + '{green}hilbish.message{reset} -> Simple notification system which can be used by other plugins and parts of the shell to notify the user of various actions.', [[ - {green}hilbish.opts{reset} -> Simple toggle or value options a user can set. - - EX: hilbish.opts.greeting = false, will cause the greeting message on start-up to not display. - ]], - [[ - {green}hilbish.runner{reset} -> The runner interface contains functions that allow the user to change how Hilbish interprets interactive input. - - The default runners can run shell script and Lua code. - ]], - [[ - Add Lua-written commands with the commander module! - Checkout the docs here -> https://rosettea.github.io/Hilbish/docs/api/commander/ - ]] +{green}hilbish.opts{reset} -> Simple toggle or value options a user can set. +You may disable the startup greeting by {invert}hilbish.opts.greeting = false{reset} +]], +[[ +{green}hilbish.runner{reset} -> The runner interface contains functions to +manage how Hilbish interprets interactive input. The default runners can run +shell script and Lua code! +]], +[[ +Add Lua-written commands with the commander module! +Check the command {blue}doc api commander{reset} or the web docs: +https://rosettea.github.io/Hilbish/docs/api/commander/ +]] } bait.catch('hilbish.init', function() if hilbish.interactive and hilbish.opts.tips then local idx = math.random(1, #hilbish.tips) - print(lunacolors.format(PREAMBLE .. "\nTip: " .. hilbish.tips[idx])) + print(lunacolors.format('{yellow}🛈 Tip:{reset} ' .. hilbish.tips[idx] .. '\n' .. postamble)) end end) From 19feda919e31012eebbd3d1dfe079d7d2ef5ad9d Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 27 Jul 2024 14:27:54 -0400 Subject: [PATCH 34/51] chore: update changelog --- CHANGELOG.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f130876..cbeb482 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ # 🎀 Changelog -## Unreleased +## [2.3.1] - 2024-07-27 +[hehe when you see it release](https://youtu.be/AaAF51Gwbxo?si=rhj2iYuQRkqDa693&t=64) + ### Added -- `nature.opts.tips` was added to randomly generate tips on start up. -Follows the pattern of motd and greeting. Displays after greeting on start up. +- `nature.opts.tips` was added to display random tips on start up. +Displayed tips can be modified via the `hilbish.tips` table. + +### Fixed +- Fix a minor regression related to the cd command not working with relative paths +- Updated the motd for 2.3 ## [2.3.0] - 2024-07-20 ### Added @@ -763,6 +769,7 @@ This input for example will prompt for more input to complete: First "stable" release of Hilbish. +[2.3.1]: https://github.com/Rosettea/Hilbish/compare/v2.3.0...v2.3.1 [2.3.0]: https://github.com/Rosettea/Hilbish/compare/v2.2.3...v2.3.0 [2.2.3]: https://github.com/Rosettea/Hilbish/compare/v2.2.2...v2.2.3 [2.2.2]: https://github.com/Rosettea/Hilbish/compare/v2.2.1...v2.2.2 From ea233facc87c61e55bca60f5dc6885f6307cc179 Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 27 Jul 2024 14:28:09 -0400 Subject: [PATCH 35/51] fix: get absolute path in fs.cd function --- golibs/fs/fs.go | 3 ++- nature/commands/cd.lua | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/golibs/fs/fs.go b/golibs/fs/fs.go index 13f972d..002be90 100644 --- a/golibs/fs/fs.go +++ b/golibs/fs/fs.go @@ -110,11 +110,12 @@ func (f *fs) fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { } path = util.ExpandHome(strings.TrimSpace(path)) + abspath, _ := filepath.Abs(path) err = os.Chdir(path) if err != nil { return nil, err } - interp.Dir(path)(f.runner) + interp.Dir(abspath)(f.runner) return c.Next(), err } diff --git a/nature/commands/cd.lua b/nature/commands/cd.lua index 22078d9..7cfe4a2 100644 --- a/nature/commands/cd.lua +++ b/nature/commands/cd.lua @@ -19,7 +19,7 @@ commander.register('cd', function (args, sinks) dirs.setOld(hilbish.cwd()) dirs.push(path) - local ok, err = pcall(function() fs.cd(fs.abs(path)) end) + local ok, err = pcall(function() fs.cd(path) end) if not ok then sinks.out:writeln(err) return 1 From 72324c27de8026779341b35d436cf4601caaa1c2 Mon Sep 17 00:00:00 2001 From: sammyette Date: Tue, 30 Jul 2024 17:57:53 -0400 Subject: [PATCH 36/51] fix: command path searching --- exec.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/exec.go b/exec.go index 446a14d..f1c5a05 100644 --- a/exec.go +++ b/exec.go @@ -287,6 +287,7 @@ func execCommand(cmd string, strms *streams) (io.Writer, io.Writer, error) { } interp.StdIO(strms.stdin, strms.stdout, strms.stderr)(runner) + interp.Env(nil)(runner) buf := new(bytes.Buffer) printer := syntax.NewPrinter() @@ -398,7 +399,7 @@ func execHandle(bg bool) interp.ExecHandlerFunc { return interp.NewExitStatus(exitcode) } - err := lookpath(args[0]) + path, err := lookpath(args[0]) if err == errNotExec { return execError{ typ: "not-executable", @@ -419,15 +420,16 @@ func execHandle(bg bool) interp.ExecHandlerFunc { killTimeout := 2 * time.Second // from here is basically copy-paste of the default exec handler from // sh/interp but with our job handling - path, err := interp.LookPathDir(hc.Dir, hc.Env, args[0]) - if err != nil { - fmt.Fprintln(hc.Stderr, err) - return interp.NewExitStatus(127) - } env := hc.Env envList := make([]string, 0, 64) env.Each(func(name string, vr expand.Variable) bool { + if name == "PATH" { + pathEnv := os.Getenv("PATH") + envList = append(envList, "PATH="+pathEnv) + return true + } + if !vr.IsSet() { // If a variable is set globally but unset in the // runner, we need to ensure it's not part of the final @@ -445,6 +447,7 @@ func execHandle(bg bool) interp.ExecHandlerFunc { } return true }) + cmd := exec.Cmd{ Path: path, Args: args, @@ -527,7 +530,7 @@ func handleExecErr(err error) (exit uint8) { return } -func lookpath(file string) error { // custom lookpath function so we know if a command is found *and* is executable +func lookpath(file string) (string, error) { // custom lookpath function so we know if a command is found *and* is executable var skip []string if runtime.GOOS == "windows" { skip = []string{"./", "../", "~/", "C:"} @@ -536,20 +539,20 @@ func lookpath(file string) error { // custom lookpath function so we know if a c } for _, s := range skip { if strings.HasPrefix(file, s) { - return findExecutable(file, false, false) + return file, findExecutable(file, false, false) } } for _, dir := range filepath.SplitList(os.Getenv("PATH")) { path := filepath.Join(dir, file) err := findExecutable(path, true, false) if err == errNotExec { - return err + return "", err } else if err == nil { - return nil + return path, nil } } - return os.ErrNotExist + return "", os.ErrNotExist } func splitInput(input string) ([]string, string) { From 137efe5c629f51e8613d3abc5203c98674f7cb7d Mon Sep 17 00:00:00 2001 From: sammyette Date: Tue, 30 Jul 2024 19:24:57 -0400 Subject: [PATCH 37/51] fix: motd typo --- nature/opts/motd.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nature/opts/motd.lua b/nature/opts/motd.lua index 6d957d3..ca08142 100644 --- a/nature/opts/motd.lua +++ b/nature/opts/motd.lua @@ -4,7 +4,7 @@ local lunacolors = require 'lunacolors' hilbish.motd = [[ Wait ... {magenta}2.3{reset} is basically the same as {red}2.2?{reset} Erm.. {blue}Ctrl-C works for Commanders,{reset} {cyan}and the sh runner has some fixes.{reset} -Just trust me bro, this is an imporant bug fix release. {red}- 🌺 sammyette{reset} +Just trust me bro, this is an important bug fix release. {red}- 🌺 sammyette{reset} ]] bait.catch('hilbish.init', function() From 0582fbd30c75e5915108df0183ac05747c69a7d9 Mon Sep 17 00:00:00 2001 From: sammyette Date: Tue, 30 Jul 2024 19:26:35 -0400 Subject: [PATCH 38/51] chore: prepare v2.3.2 --- CHANGELOG.md | 7 ++++++- vars.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbeb482..14e4d64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ # 🎀 Changelog +## [2.3.2] - 2024-07-30 +### Fixed +- Command path searching due to 2.3 changes to the shell interpreter + ## [2.3.1] - 2024-07-27 [hehe when you see it release](https://youtu.be/AaAF51Gwbxo?si=rhj2iYuQRkqDa693&t=64) ### Added -- `nature.opts.tips` was added to display random tips on start up. +- `hilbish.opts.tips` was added to display random tips on start up. Displayed tips can be modified via the `hilbish.tips` table. ### Fixed @@ -769,6 +773,7 @@ This input for example will prompt for more input to complete: First "stable" release of Hilbish. +[2.3.1]: https://github.com/Rosettea/Hilbish/compare/v2.3.1...v2.3.2 [2.3.1]: https://github.com/Rosettea/Hilbish/compare/v2.3.0...v2.3.1 [2.3.0]: https://github.com/Rosettea/Hilbish/compare/v2.2.3...v2.3.0 [2.2.3]: https://github.com/Rosettea/Hilbish/compare/v2.2.2...v2.2.3 diff --git a/vars.go b/vars.go index 6b4bba8..5398eb8 100644 --- a/vars.go +++ b/vars.go @@ -11,7 +11,7 @@ var ( // Version info var ( - ver = "v2.3.1" + ver = "v2.3.2" releaseName = "Alyssum" gitCommit string From fc6a9a33e1df13a316b929a8d2b4ab526fb99448 Mon Sep 17 00:00:00 2001 From: sammyette Date: Thu, 15 Aug 2024 12:38:35 -0400 Subject: [PATCH 39/51] chore: update dependencies (fixes #318) --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 985f2e2..9043659 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( golang.org/x/text v0.14.0 // indirect ) -replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240720131751-805c301321fd +replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240815163633-562273e09b73 replace github.com/maxlandon/readline => ./readline diff --git a/go.sum b/go.sum index 136f827..6ac9397 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749 h1:jIFnWBTsYw8s7RX7H2AOXjDVhWP3ol7OzUVaPN2KnGI= github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749/go.mod h1:9jzpYPiU2is0HVGCiuIOBSXdergHUW44IEjmuN1UrIE= -github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240720131751-805c301321fd h1:THNle0FR2g7DMO1y3Bx1Zr7rYeiLXt3st3UkxEsMzL4= -github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240720131751-805c301321fd/go.mod h1:YZalN5H7WNQw3DGij6IvHsEhn5YMW7M2FCwG6gnfKy4= +github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240815163633-562273e09b73 h1:zTTUJqNnrF2qf4LgygN8Oae5Uxn6ewH0hA8jyTCHfXw= +github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240815163633-562273e09b73/go.mod h1:YZalN5H7WNQw3DGij6IvHsEhn5YMW7M2FCwG6gnfKy4= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo= github.com/arnodel/strftime v0.1.6 h1:0hc0pUvk8KhEMXE+htyaOUV42zNcf/csIbjzEFCJqsw= From db851cf4f833de11dc72fc20821919ff45028391 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 16 Aug 2024 15:23:55 -0400 Subject: [PATCH 40/51] chore: bump to 2.4 --- vars.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vars.go b/vars.go index 5398eb8..86ed253 100644 --- a/vars.go +++ b/vars.go @@ -11,8 +11,8 @@ var ( // Version info var ( - ver = "v2.3.2" - releaseName = "Alyssum" + ver = "v2.4.0" + releaseName = "Moonflower" gitCommit string gitBranch string From e6b88816fdb3a827ac09b1f7f2f2be178b3ca421 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 16 Aug 2024 15:25:35 -0400 Subject: [PATCH 41/51] chore: add 2.4 motd (work in progress) --- nature/opts/motd.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nature/opts/motd.lua b/nature/opts/motd.lua index ca08142..064ef93 100644 --- a/nature/opts/motd.lua +++ b/nature/opts/motd.lua @@ -2,9 +2,7 @@ local bait = require 'bait' local lunacolors = require 'lunacolors' hilbish.motd = [[ -Wait ... {magenta}2.3{reset} is basically the same as {red}2.2?{reset} -Erm.. {blue}Ctrl-C works for Commanders,{reset} {cyan}and the sh runner has some fixes.{reset} -Just trust me bro, this is an important bug fix release. {red}- 🌺 sammyette{reset} +{magenta}Hilbish{reset} blooms in the {blue}midnight.{reset} ]] bait.catch('hilbish.init', function() From a7ba2fdf1a6f79d81e48c219cd4efce022bdfde2 Mon Sep 17 00:00:00 2001 From: sammyette Date: Fri, 16 Aug 2024 15:26:10 -0400 Subject: [PATCH 42/51] fix: add newline at the end of input if in an unfinished heredoc (#322) and define (or fix) the behavior of input ending with a slash it will now add a newline at the end of input always --- CHANGELOG.md | 7 +++++ docs/features/runner-mode.md | 13 --------- exec.go | 56 ++++++++++++++++++++++-------------- main.go | 17 ++++++++--- runnermode.go | 25 +++++++++------- 5 files changed, 68 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14e4d64..f9d4df8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # 🎀 Changelog +## Unreleased +### Fixed +- Heredocs having issues + +### Added +- Adding `\` at the end of input will add a newline and prompt for more input. + ## [2.3.2] - 2024-07-30 ### Fixed - Command path searching due to 2.3 changes to the shell interpreter diff --git a/docs/features/runner-mode.md b/docs/features/runner-mode.md index 0f7a8dd..ec804c1 100644 --- a/docs/features/runner-mode.md +++ b/docs/features/runner-mode.md @@ -33,19 +33,6 @@ needs to run interactive input. For more detail, see the [API documentation](../ The `hilbish.runner` interface is an alternative to using `hilbish.runnerMode` and also provides the shell script and Lua runner functions that Hilbish itself uses. -A runner function is expected to return a table with the following values: -- `exitCode` (number): Exit code of the command -- `input` (string): The text input of the user. This is used by Hilbish to append extra input, in case -more is requested. -- `err` (string): A string that represents an error from the runner. -This should only be set when, for example, there is a syntax error. -It can be set to a few special values for Hilbish to throw the right -hooks and have a better looking message. - - `: not-found` will throw a `command.not-found` hook - based on what `` is. - - `: not-executable` will throw a `command.not-executable` hook. -- `continue` (boolean): Whether Hilbish should prompt the user for no input - ## Functions These are the "low level" functions for the `hilbish.runner` interface. diff --git a/exec.go b/exec.go index f1c5a05..357c143 100644 --- a/exec.go +++ b/exec.go @@ -98,6 +98,7 @@ func runInput(input string, priv bool) { var exitCode uint8 var err error var cont bool + var newline bool // save incase it changes while prompting (For some reason) currentRunner := runnerMode if currentRunner.Type() == rt.StringType { @@ -108,9 +109,9 @@ func runInput(input string, priv bool) { cmdFinish(0, input, priv) return } - input, exitCode, cont, err = handleSh(input) + input, exitCode, cont, newline, err = handleSh(input) case "hybridRev": - _, _, _, err = handleSh(input) + _, _, _, _, err = handleSh(input) if err == nil { cmdFinish(0, input, priv) return @@ -119,12 +120,12 @@ func runInput(input string, priv bool) { case "lua": input, exitCode, err = handleLua(input) case "sh": - input, exitCode, cont, err = handleSh(input) + input, exitCode, cont, newline, err = handleSh(input) } } else { // can only be a string or function so var runnerErr error - input, exitCode, cont, runnerErr, err = runLuaRunner(currentRunner, input) + input, exitCode, cont, newline, runnerErr, err = runLuaRunner(currentRunner, input) if err != nil { fmt.Fprintln(os.Stderr, err) cmdFinish(124, input, priv) @@ -137,15 +138,15 @@ func runInput(input string, priv bool) { } if cont { - input, err = reprompt(input) + input, err = continuePrompt(input, newline) if err == nil { goto rerun } else if err == io.EOF { - return + lr.SetPrompt(fmtPrompt(prompt)) } } - if err != nil { + if err != nil && err != io.EOF { if exErr, ok := isExecError(err); ok { hooks.Emit("command." + exErr.typ, exErr.cmd) } else { @@ -155,26 +156,28 @@ func runInput(input string, priv bool) { cmdFinish(exitCode, input, priv) } -func reprompt(input string) (string, error) { +func reprompt(input string, newline bool) (string, error) { for { - in, err := continuePrompt(strings.TrimSuffix(input, "\\")) + /* + if strings.HasSuffix(input, "\\") { + input = strings.TrimSuffix(input, "\\") + "\n" + } + */ + in, err := continuePrompt(input, newline) if err != nil { lr.SetPrompt(fmtPrompt(prompt)) return input, err } - if strings.HasSuffix(in, "\\") { - continue - } return in, nil } } -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, newline bool, runnerErr, 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 "", 124, false, false, nil, err } var runner *rt.Table @@ -202,6 +205,10 @@ func runLuaRunner(runr rt.Value, userInput string) (input string, exitCode uint8 if c, ok := runner.Get(rt.StringValue("continue")).TryBool(); ok { continued = c } + + if nl, ok := runner.Get(rt.StringValue("newline")).TryBool(); ok { + newline = nl + } return } @@ -232,35 +239,40 @@ func handleLua(input string) (string, uint8, error) { return cmdString, 125, err } -func handleSh(cmdString string) (input string, exitCode uint8, cont bool, runErr error) { +func handleSh(cmdString string) (input string, exitCode uint8, cont bool, newline bool, runErr error) { shRunner := hshMod.Get(rt.StringValue("runner")).AsTable().Get(rt.StringValue("sh")) var err error - input, exitCode, cont, runErr, err = runLuaRunner(shRunner, cmdString) + input, exitCode, cont, newline, runErr, err = runLuaRunner(shRunner, cmdString) if err != nil { runErr = err } return } -func execSh(cmdString string) (string, uint8, bool, error) { +func execSh(cmdString string) (input string, exitcode uint8, cont bool, newline bool, e error) { _, _, err := execCommand(cmdString, nil) if err != nil { // If input is incomplete, start multiline prompting if syntax.IsIncomplete(err) { if !interactive { - return cmdString, 126, false, err + return cmdString, 126, false, false, err } - return cmdString, 126, true, err + + newline := false + if strings.Contains(err.Error(), "unclosed here-document") { + newline = true + } + return cmdString, 126, true, newline, err } else { if code, ok := interp.IsExitStatus(err); ok { - return cmdString, code, false, nil + return cmdString, code, false, false, nil } else { - return cmdString, 126, false, err + return cmdString, 126, false, false, err } } } - return cmdString, 0, false, nil + return cmdString, 0, false, false, nil } // Run command in sh interpreter diff --git a/main.go b/main.go index 41d1d35..1bddfc4 100644 --- a/main.go +++ b/main.go @@ -223,8 +223,9 @@ input: } if strings.HasSuffix(input, "\\") { + print("\n") for { - input, err = continuePrompt(input) + input, err = continuePrompt(strings.TrimSuffix(input, "\\") + "\n", false) if err != nil { running = true lr.SetPrompt(fmtPrompt(prompt)) @@ -248,16 +249,24 @@ input: exit(0) } -func continuePrompt(prev string) (string, error) { +func continuePrompt(prev string, newline bool) (string, error) { hooks.Emit("multiline", nil) lr.SetPrompt(multilinePrompt) + cont, err := lr.Read() if err != nil { return "", err } - cont = strings.TrimSpace(cont) - return prev + strings.TrimSuffix(cont, "\n"), nil + if newline { + cont = "\n" + cont + } + + if strings.HasSuffix(cont, "\\") { + cont = strings.TrimSuffix(cont, "\\") + "\n" + } + + return prev + cont, nil } // This semi cursed function formats our prompt (obviously) diff --git a/runnermode.go b/runnermode.go index 55adfdc..fb8bcf4 100644 --- a/runnermode.go +++ b/runnermode.go @@ -21,16 +21,18 @@ A runner is passed the input and has to return a table with these values. All are not required, only the useful ones the runner needs to return. (So if there isn't an error, just omit `err`.) -- `exitCode` (number): A numerical code to indicate the exit result. -- `input` (string): The user input. This will be used to add -to the history. -- `err` (string): A string to indicate an interal error for the runner. -It can be set to a few special values for Hilbish to throw the right hooks and have a better looking message: - -`[command]: not-found` will throw a command.not-found hook based on what `[command]` is. - -`[command]: not-executable` will throw a command.not-executable hook. -- `continue` (boolean): Whether to prompt the user for more input. +- `exitCode` (number): Exit code of the command +- `input` (string): The text input of the user. This is used by Hilbish to append extra input, in case +more is requested. +- `err` (string): A string that represents an error from the runner. +This should only be set when, for example, there is a syntax error. +It can be set to a few special values for Hilbish to throw the right +hooks and have a better looking message. + - `: not-found` will throw a `command.not-found` hook + based on what `` is. + - `: not-executable` will throw a `command.not-executable` hook. +- `continue` (boolean): Whether Hilbish should prompt the user for no input +- `newline` (boolean): Whether a newline should be added at the end of `input`. Here is a simple example of a fennel runner. It falls back to shell script if fennel eval has an error. @@ -85,7 +87,7 @@ func shRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return nil, err } - _, exitCode, cont, err := execSh(aliases.Resolve(cmd)) + _, exitCode, cont, newline, err := execSh(aliases.Resolve(cmd)) var luaErr rt.Value = rt.NilValue if err != nil { luaErr = rt.StringValue(err.Error()) @@ -94,6 +96,7 @@ func shRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { runnerRet.Set(rt.StringValue("input"), rt.StringValue(cmd)) runnerRet.Set(rt.StringValue("exitCode"), rt.IntValue(int64(exitCode))) runnerRet.Set(rt.StringValue("continue"), rt.BoolValue(cont)) + runnerRet.Set(rt.StringValue("newline"), rt.BoolValue(newline)) runnerRet.Set(rt.StringValue("err"), luaErr) return c.PushingNext(t.Runtime, rt.TableValue(runnerRet)), nil From 824f5bd06d6832b4d25b7def038ce639ec03a633 Mon Sep 17 00:00:00 2001 From: TorchedSammy Date: Fri, 16 Aug 2024 19:26:30 +0000 Subject: [PATCH 43/51] docs: [ci] generate new docs --- docs/api/hilbish/hilbish.runner.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/api/hilbish/hilbish.runner.md b/docs/api/hilbish/hilbish.runner.md index b5cfde4..8c89a52 100644 --- a/docs/api/hilbish/hilbish.runner.md +++ b/docs/api/hilbish/hilbish.runner.md @@ -21,16 +21,18 @@ A runner is passed the input and has to return a table with these values. All are not required, only the useful ones the runner needs to return. (So if there isn't an error, just omit `err`.) -- `exitCode` (number): A numerical code to indicate the exit result. -- `input` (string): The user input. This will be used to add -to the history. -- `err` (string): A string to indicate an interal error for the runner. -It can be set to a few special values for Hilbish to throw the right hooks and have a better looking message: - -`[command]: not-found` will throw a command.not-found hook based on what `[command]` is. - -`[command]: not-executable` will throw a command.not-executable hook. -- `continue` (boolean): Whether to prompt the user for more input. +- `exitCode` (number): Exit code of the command +- `input` (string): The text input of the user. This is used by Hilbish to append extra input, in case +more is requested. +- `err` (string): A string that represents an error from the runner. +This should only be set when, for example, there is a syntax error. +It can be set to a few special values for Hilbish to throw the right +hooks and have a better looking message. + - `\: not-found` will throw a `command.not-found` hook + based on what `\` is. + - `\: not-executable` will throw a `command.not-executable` hook. +- `continue` (boolean): Whether Hilbish should prompt the user for no input +- `newline` (boolean): Whether a newline should be added at the end of `input`. Here is a simple example of a fennel runner. It falls back to shell script if fennel eval has an error. From edbc758c67650d2bfaa416fe0e259bd8cbd90e3a Mon Sep 17 00:00:00 2001 From: sammy Date: Sat, 31 Aug 2024 16:50:58 -0400 Subject: [PATCH 44/51] docs: use only 1 screenshot --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 4566c30..c0c0b3d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,6 @@ and aims to be infinitely configurable. If something isn't, open an issue! # Screenshots
-
# Getting Hilbish From 1e01580d8f492d82c29a8366b2fb8b8ae8b520bb Mon Sep 17 00:00:00 2001 From: ShalokShalom Date: Sun, 1 Sep 2024 00:05:24 +0200 Subject: [PATCH 45/51] docs: add info about runner mode (#325) --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c0c0b3d..aed2dfc 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,19 @@
Hilbish is an extensible shell designed to be highly customizable. -It is configured in Lua and provides a good range of features. -It aims to be easy to use for anyone but powerful enough for -those who need it. + +It is configured in Lua, and provides a good range of features. +It aims to be easy to use for anyone, and powerful enough for +those who need more. The motivation for choosing Lua was that its simpler and better to use -than old shell script. It's fine for basic interactive shell uses, -but that's the only place Hilbish has shell script; everything else is Lua -and aims to be infinitely configurable. If something isn't, open an issue! +than old shell scripts. It's fine for basic interactive shell uses, +and supports [both Lua and Sh interactively](https://rosettea.github.io/Hilbish/docs/features/runner-mode/). + +That's the only place Hilbish can use traditional shell syntax though; +everything else is Lua and aims to be infinitely configurable. + +If something isn't, open an issue! # Screenshots
From 46968e632bc050acd332bbe02dba2136470f9c76 Mon Sep 17 00:00:00 2001 From: sammyette Date: Sun, 3 Nov 2024 23:24:18 -0400 Subject: [PATCH 46/51] fix: bump golua (closes #326) --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9043659..cc88c8e 100644 --- a/go.mod +++ b/go.mod @@ -34,4 +34,4 @@ replace github.com/maxlandon/readline => ./readline replace layeh.com/gopher-luar => github.com/layeh/gopher-luar v1.0.10 -replace github.com/arnodel/golua => github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749 +replace github.com/arnodel/golua => github.com/Rosettea/golua v0.0.0-20241104031959-5551ea280f23 diff --git a/go.sum b/go.sum index 6ac9397..b4b7a91 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749 h1:jIFnWBTsYw8s7RX7H2AOXjDVhWP3ol7OzUVaPN2KnGI= -github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749/go.mod h1:9jzpYPiU2is0HVGCiuIOBSXdergHUW44IEjmuN1UrIE= +github.com/Rosettea/golua v0.0.0-20241104031959-5551ea280f23 h1:mUZnT0gmDEmTkqXsbnDbuJ3CNil7DCOMiCQYgjbKIdI= +github.com/Rosettea/golua v0.0.0-20241104031959-5551ea280f23/go.mod h1:9jzpYPiU2is0HVGCiuIOBSXdergHUW44IEjmuN1UrIE= github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240815163633-562273e09b73 h1:zTTUJqNnrF2qf4LgygN8Oae5Uxn6ewH0hA8jyTCHfXw= github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240815163633-562273e09b73/go.mod h1:YZalN5H7WNQw3DGij6IvHsEhn5YMW7M2FCwG6gnfKy4= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= From dbb45a1947f5b5f054a2462b6d28b9d2dd970c0e Mon Sep 17 00:00:00 2001 From: sammyette Date: Mon, 4 Nov 2024 06:51:20 -0400 Subject: [PATCH 47/51] chore: revert "chore: bump to 2.4" This reverts commit db851cf4f833de11dc72fc20821919ff45028391. --- vars.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vars.go b/vars.go index 86ed253..5398eb8 100644 --- a/vars.go +++ b/vars.go @@ -11,8 +11,8 @@ var ( // Version info var ( - ver = "v2.4.0" - releaseName = "Moonflower" + ver = "v2.3.2" + releaseName = "Alyssum" gitCommit string gitBranch string From 7fc3f4a569405c86675978341a0c008069b994b9 Mon Sep 17 00:00:00 2001 From: sammyette Date: Mon, 4 Nov 2024 06:51:31 -0400 Subject: [PATCH 48/51] chore: revert "chore: add 2.4 motd (work in progress)" This reverts commit e6b88816fdb3a827ac09b1f7f2f2be178b3ca421. --- nature/opts/motd.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nature/opts/motd.lua b/nature/opts/motd.lua index 064ef93..ca08142 100644 --- a/nature/opts/motd.lua +++ b/nature/opts/motd.lua @@ -2,7 +2,9 @@ local bait = require 'bait' local lunacolors = require 'lunacolors' hilbish.motd = [[ -{magenta}Hilbish{reset} blooms in the {blue}midnight.{reset} +Wait ... {magenta}2.3{reset} is basically the same as {red}2.2?{reset} +Erm.. {blue}Ctrl-C works for Commanders,{reset} {cyan}and the sh runner has some fixes.{reset} +Just trust me bro, this is an important bug fix release. {red}- 🌺 sammyette{reset} ]] bait.catch('hilbish.init', function() From ac7c97442e89cc9247a0f43adf8b983e32d01f0c Mon Sep 17 00:00:00 2001 From: sammyette Date: Mon, 4 Nov 2024 06:54:09 -0400 Subject: [PATCH 49/51] chore: bump for bugfix release --- CHANGELOG.md | 5 +++-- vars.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9d4df8..adbf121 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # 🎀 Changelog -## Unreleased +## [2.3.3] - 2024-11-04 ### Fixed - Heredocs having issues @@ -780,7 +780,8 @@ This input for example will prompt for more input to complete: First "stable" release of Hilbish. -[2.3.1]: https://github.com/Rosettea/Hilbish/compare/v2.3.1...v2.3.2 +[2.3.3]: https://github.com/Rosettea/Hilbish/compare/v2.3.2...v2.3.3 +[2.3.2]: https://github.com/Rosettea/Hilbish/compare/v2.3.1...v2.3.2 [2.3.1]: https://github.com/Rosettea/Hilbish/compare/v2.3.0...v2.3.1 [2.3.0]: https://github.com/Rosettea/Hilbish/compare/v2.2.3...v2.3.0 [2.2.3]: https://github.com/Rosettea/Hilbish/compare/v2.2.2...v2.2.3 diff --git a/vars.go b/vars.go index 5398eb8..55d71a7 100644 --- a/vars.go +++ b/vars.go @@ -11,7 +11,7 @@ var ( // Version info var ( - ver = "v2.3.2" + ver = "v2.3.3" releaseName = "Alyssum" gitCommit string From 36ce05e85a862f12b206a4a336fba94834f7372c Mon Sep 17 00:00:00 2001 From: CelestialCrafter Date: Fri, 22 Nov 2024 18:20:43 -0600 Subject: [PATCH 50/51] fix: handle completion info check error (#330) * fix: handle completion info check error fixes Rosettea/Hilbish#329 * make changelog more descriptive --- CHANGELOG.md | 4 ++++ complete.go | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adbf121..fd848c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 🎀 Changelog +## Unreleased +### Fixed +- Skip over file and prevent panic if info cannot be retrieved during file completion (due to permission error or anything else) + ## [2.3.3] - 2024-11-04 ### Fixed - Heredocs having issues diff --git a/complete.go b/complete.go index 1c40b20..86938cb 100644 --- a/complete.go +++ b/complete.go @@ -157,9 +157,12 @@ func matchPath(query string) ([]string, string) { files, _ := os.ReadDir(path) for _, entry := range files { - // should we handle errors here? file, err := entry.Info() - if err == nil && file.Mode() & os.ModeSymlink != 0 { + if err != nil { + continue + } + + if file.Mode() & os.ModeSymlink != 0 { path, err := filepath.EvalSymlinks(filepath.Join(path, file.Name())) if err == nil { file, err = os.Lstat(path) From c969f5ed155c93c55bdbc5a43c17d4876c0ac6eb Mon Sep 17 00:00:00 2001 From: sammy Date: Sun, 22 Dec 2024 08:09:57 -0800 Subject: [PATCH 51/51] feat: complete hint text on right arrow (#328) --- CHANGELOG.md | 3 +++ readline/hint.go | 7 +++++++ readline/readline.go | 3 +++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd848c5..87a7c47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # 🎀 Changelog ## Unreleased +### Added +- Forward/Right arrow key will fill in hint text (#327) + ### Fixed - Skip over file and prevent panic if info cannot be retrieved during file completion (due to permission error or anything else) diff --git a/readline/hint.go b/readline/hint.go index 6c6a67c..d0c54fe 100644 --- a/readline/hint.go +++ b/readline/hint.go @@ -56,3 +56,10 @@ func (rl *Instance) resetHintText() { //rl.hintY = 0 rl.hintText = []rune{} } + +func (rl *Instance) insertHintText() { + if len(rl.hintText) != 0 { + // fill in hint text + rl.insert(rl.hintText) + } +} diff --git a/readline/readline.go b/readline/readline.go index 627bff4..7282071 100644 --- a/readline/readline.go +++ b/readline/readline.go @@ -707,6 +707,9 @@ func (rl *Instance) escapeSeq(r []rune) { rl.renderHelpers() return } + + rl.insertHintText() + if (rl.modeViMode == VimInsert && rl.pos < len(rl.line)) || (rl.modeViMode != VimInsert && rl.pos < len(rl.line)-1) { rl.moveCursorByAdjust(1)