interactive command runner customization
The runner interface contains functions that allow the user to change how Hilbish interprets interactive input. Users can add and change the default runner for interactive input to any language or script of their choosing. A good example is using it to write command in Fennel.
Runners are functions that evaluate user input. The default runners in Hilbish can run shell script and Lua code.
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): Exit code of the commandinput (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.\<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 Hilbish should prompt the user for no inputnewline (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.
1local fennel = require 'fennel'
2
3hilbish.runnerMode(function(input)
4 local ok = pcall(fennel.eval, input)
5 if ok then
6 return {
7 input = input
8 }
9 end
10
11 return hilbish.runner.sh(input)
12end)
| setMode(cb) | This is the same as the hilbish.runnerMode function. |
| lua(cmd) | Evaluates cmd as Lua input. This is the same as using dofile |
| sh(cmd) | Runs a command in Hilbish’s shell script interpreter. |
| hilbish.runner.getCurrent() | Returns the current runner by name. |
| hilbish.runner.setCurrent(name) | Sets the current interactive/command line runner mode. |
| hilbish.runner.add(name, runner) | Adds a runner to the table of available runners. If runner is a table, |
| hilbish.runner.get(name) | Get a runner by name. |
| hilbish.runner.set(name, runner) | Sets a runner by name. The runner table must have the run function in it. |
| hilbish.runner.exec(cmd, runnerName) | Executes cmd with a runner. If runnerName isn’t passed, it uses |
Evaluates cmd as Lua input. This is the same as using dofile
or load, but is appropriated for the runner interface.
string cmd
Runs a command in Hilbish’s shell script interpreter.
This is the equivalent of using source.
string cmd
Returns the current runner by name.
This function has no parameters.
Sets the current interactive/command line runner mode.
name string
Adds a runner to the table of available runners. If runner is a table, it must have the run function in it.
name string
runner function
Sets a runner by name. The runner table must have the run function in it.
name string
runner table
Want to help improve this page? Create an issue.