diff --git a/docs/api/hilbish/_index.md b/docs/api/hilbish/_index.md index 8c0218f9..a5d31270 100644 --- a/docs/api/hilbish/_index.md +++ b/docs/api/hilbish/_index.md @@ -30,6 +30,8 @@ interfaces and functions which directly relate to shell functionality. |read(prompt) -> input (string)|Read input from the user, using Hilbish's line editor/input reader.| |timeout(cb, time) -> @Timer|Executed the `cb` function after a period of `time`.| |which(name) -> string|Checks if `name` is a valid command.| +|runnerMode(mode)|Sets the execution/runner mode for interactive Hilbish.| +|run(cmd, streams)|Runs `cmd` in Hilbish's shell script interpreter.| ## Static module fields ||| @@ -475,3 +477,65 @@ Writes data to a sink. #### writeln(str) Writes data to a sink with a newline at the end. +
+
+

+hilbish.run(cmd, streams) + + + +

+ +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. +#### Parameters +`cmd` **`string`** + + +`streams` **`table|boolean`** + + +#### 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 +}) +``` +
+ +
+
+

+hilbish.runnerMode(mode) + + + +

+ +Sets the execution/runner mode for interactive Hilbish. +**NOTE: This function is deprecated and will be removed in 3.0** +Use `hilbish.runner.setCurrent` instead. +This determines whether Hilbish wll try to run input as Lua +and/or sh or only do one of either. +Accepted values for mode are hybrid (the default), hybridRev (sh first then Lua), +sh, and lua. It also accepts a function, to which if it is passed one +will call it to execute user input instead. +Read [about runner mode](../features/runner-mode) for more information. +#### Parameters +`mode` **`string|function`** + + +
+ diff --git a/docs/api/hilbish/hilbish.abbr.md b/docs/api/hilbish/hilbish.abbr.md new file mode 100644 index 00000000..8e88c190 --- /dev/null +++ b/docs/api/hilbish/hilbish.abbr.md @@ -0,0 +1,67 @@ +--- +title: Module hilbish.abbr +description: command line abbreviations +layout: doc +menu: + docs: + parent: "API" +--- + + +## Introduction +The abbr module manages Hilbish abbreviations. These are words that can be replaced +with longer command line strings when entered. +As an example, `git push` can be abbreviated to `gp`. When the user types +`gp` into the command line, after hitting space or enter, it will expand to `git push`. +Abbreviations can be used as an alternative to aliases. They are saved entirely in the history +Instead of the aliased form of the same command. + +## Functions +||| +|----|----| +|remove(abbr)|Removes the named `abbr`.| +|add(abbr, expanded|function, opts)|Adds an abbreviation. The `abbr` is the abbreviation itself,| +
+
+

+hilbish.abbr.add(abbr, expanded|function, opts) + + + +

+ +Adds an abbreviation. The `abbr` is the abbreviation itself, +while `expanded` is what the abbreviation should expand to. +It can be either a function or a string. If it is a function, it will expand to what +the function returns. +`opts` is a table that accepts 1 key: `anywhere`. +`opts.anywhere` defines whether the abbr expands anywhere in the command line or not, +whereas the default behavior is only at the beginning of the line +#### Parameters +`abbr` **`string`** + + +`expanded|function` **`string`** + + +`opts` **`table`** + + +
+ +
+
+

+hilbish.abbr.remove(abbr) + + + +

+ +Removes the named `abbr`. +#### Parameters +`abbr` **`string`** + + +
+ diff --git a/docs/api/hilbish/hilbish.messages.md b/docs/api/hilbish/hilbish.messages.md new file mode 100644 index 00000000..705cfa2c --- /dev/null +++ b/docs/api/hilbish/hilbish.messages.md @@ -0,0 +1,135 @@ +--- +title: Module hilbish.messages +description: simplistic message passing +layout: doc +menu: + docs: + parent: "API" +--- + + +## Introduction +The messages interface defines a way for Hilbish-integrated commands, +user config and other tasks to send notifications to alert the user.z +The `hilbish.message` type is a table with the following keys: +`title` (string): A title for the message notification. +`text` (string): The contents of the message. +`channel` (string): States the origin of the message, `hilbish.*` is reserved for Hilbish tasks. +`summary` (string): A short summary of the `text`. +`icon` (string): Unicode (preferably standard emoji) icon for the message notification +`read` (boolean): Whether the full message has been read or not. + +## Functions +||| +|----|----| +|unreadCount()|Returns the amount of unread messages.| +|send(message)|Sends a message.| +|readAll()|Marks all messages as read.| +|read(idx)|Marks a message at `idx` as read.| +|delete(idx)|Deletes the message at `idx`.| +|clear()|Deletes all messages.| +|all()|Returns all messages.| +
+
+

+hilbish.messages.all() + + + +

+ +Returns all messages. +#### Parameters +This function has no parameters. +
+ +
+
+

+hilbish.messages.clear() + + + +

+ +Deletes all messages. +#### Parameters +This function has no parameters. +
+ +
+
+

+hilbish.messages.delete(idx) + + + +

+ +Deletes the message at `idx`. +#### Parameters +`idx` **`number`** + + +
+ +
+
+

+hilbish.messages.read(idx) + + + +

+ +Marks a message at `idx` as read. +#### Parameters +`idx` **`number`** + + +
+ +
+
+

+hilbish.messages.readAll() + + + +

+ +Marks all messages as read. +#### Parameters +This function has no parameters. +
+ +
+
+

+hilbish.messages.send(message) + + + +

+ +Sends a message. +#### Parameters +`message` **`hilbish.message`** + + +
+ +
+
+

+hilbish.messages.unreadCount() + + + +

+ +Returns the amount of unread messages. +#### Parameters +This function has no parameters. +
+ diff --git a/docs/api/hilbish/hilbish.processors.md b/docs/api/hilbish/hilbish.processors.md new file mode 100644 index 00000000..43dfecb4 --- /dev/null +++ b/docs/api/hilbish/hilbish.processors.md @@ -0,0 +1,39 @@ +--- +title: Module hilbish.processors +description: No description. +layout: doc +menu: + docs: + parent: "API" +--- + +
+
+

+hilbish.processors.add() + + + +

+ + +#### Parameters +This function has no parameters. +
+ +
+
+

+hilbish.processors.execute() + + + +

+ +Run all command processors, in order by priority. +It returns the processed command (which may be the same as the passed command) +and a boolean which states whether to proceed with command execution. +#### Parameters +This function has no parameters. +
+ diff --git a/docs/api/hilbish/hilbish.runner.md b/docs/api/hilbish/hilbish.runner.md index 2e437984..4ba49993 100644 --- a/docs/api/hilbish/hilbish.runner.md +++ b/docs/api/hilbish/hilbish.runner.md @@ -55,6 +55,15 @@ end) ||| |----|----| |lua(cmd)|Evaluates `cmd` as Lua input. This is the same as using `dofile`| +|sh()|nil| +|setMode(mode)|**NOTE: This function is deprecated and will be removed in 3.0**| +|setCurrent(name)|Sets Hilbish's runner mode by name.| +|set(name, runner)|*Sets* a runner by name. The difference between this function and| +|run(input, priv)|Runs `input` with the currently set Hilbish runner.| +|getCurrent()|Returns the current runner by name.| +|get(name)|Get a runner by name.| +|exec(cmd, runnerName)|Executes `cmd` with a runner.| +|add(name, runner)|Adds a runner to the table of available runners.|
@@ -74,3 +83,165 @@ or `load`, but is appropriated for the runner interface.
+
+
+

+hilbish.runner.add(name, runner) + + + +

+ +Adds a runner to the table of available runners. +If runner is a table, it must have the run function in it. +#### Parameters +`name` **`string`** + Name of the runner + +`runner` **`function|table`** + + +
+ +
+
+

+hilbish.runner.exec(cmd, runnerName) + + + +

+ +Executes `cmd` with a runner. +If `runnerName` is not specified, it uses the default Hilbish runner. +#### Parameters +`cmd` **`string`** + + +`runnerName` **`string?`** + + +
+ +
+
+

+hilbish.runner.get(name) + + + +

+ +Get a runner by name. +#### Parameters +`name` **`string`** + Name of the runner to retrieve. + +
+ +
+
+

+hilbish.runner.getCurrent() + + + +

+ +Returns the current runner by name. +#### Parameters +This function has no parameters. +
+ +
+
+

+hilbish.runner.run(input, priv) + + + +

+ +Runs `input` with the currently set Hilbish runner. +This method is how Hilbish executes commands. +`priv` is an optional boolean used to state if the input should be saved to history. +#### Parameters +`input` **`string`** + + +`priv` **`bool`** + + +
+ +
+
+

+hilbish.runner.set(name, runner) + + + +

+ +*Sets* a runner by name. The difference between this function and +add, is set will *not* check if the named runner exists. +The runner table must have the run function in it. +#### Parameters +`name` **`string`** + + +`runner` **`table`** + + +
+ +
+
+

+hilbish.runner.setCurrent(name) + + + +

+ +Sets Hilbish's runner mode by name. +#### Parameters +`name` **`string`** + + +
+ +
+
+

+hilbish.runner.setMode(mode) + + + +

+ +**NOTE: This function is deprecated and will be removed in 3.0** +Use `hilbish.runner.setCurrent` instead. +This is the same as the `hilbish.runnerMode` function. +It takes a callback, which will be used to execute all interactive input. +Or a string which names the runner mode to use. +#### Parameters +`mode` **`string|function`** + + +
+ +
+
+

+hilbish.runner.sh() + + + +

+ + +#### Parameters +This function has no parameters. +
+ diff --git a/nature/init.lua b/nature/init.lua index 08108824..4f973f33 100644 --- a/nature/init.lua +++ b/nature/init.lua @@ -95,16 +95,3 @@ end) bait.catch('command.not-executable', function(cmd) print(string.format('hilbish: %s: not executable', cmd)) end) - -print 'we are at the end' -while true do - print 'reading input' - local ok, res = pcall(function() return hilbish.editor:read() end) - if not ok then - print(res) - print(res == 'EOF') - os.exit(0) - end - - print(ok, res) -end