interfaces and functions which directly relate to shell functionality.</p><h3id=functionsclass=heading>Functions
<ahref=#functionsclass=heading-link><iclass="fas fa-paperclip"></i></a></h3><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><ahref=#alias>alias(cmd, orig)</a></td><td>Sets an alias, with a name of <code>cmd</code> to another command.</td></tr><tr><td><ahref=#appendPath>appendPath(dir)</a></td><td>Appends the provided dir to the command path (<code>$PATH</code>)</td></tr><tr><td><ahref=#complete>complete(scope, cb)</a></td><td>Registers a completion handler for the specified scope.</td></tr><tr><td><ahref=#cwd>cwd() -> string</a></td><td>Returns the current directory of the shell.</td></tr><tr><td><ahref=#exec>exec(cmd)</a></td><td>Replaces the currently running Hilbish instance with the supplied command.</td></tr><tr><td><ahref=#goro>goro(fn)</a></td><td>Puts <code>fn</code> in a Goroutine.</td></tr><tr><td><ahref=#highlighter>highlighter(line)</a></td><td>Line highlighter handler.</td></tr><tr><td><ahref=#hinter>hinter(line, pos)</a></td><td>The command line hint handler. It gets called on every key insert to</td></tr><tr><td><ahref=#inputMode>inputMode(mode)</a></td><td>Sets the input mode for Hilbish’s line reader.</td></tr><tr><td><ahref=#interval>interval(cb, time) -> @Timer</a></td><td>Runs the <code>cb</code> function every specified amount of <code>time</code>.</td></tr><tr><td><ahref=#multiprompt>multiprompt(str)</a></td><td>Changes the text prompt when Hilbish asks for more input.</td></tr><tr><td><ahref=#prependPath>prependPath(dir)</a></td><td>Prepends <code>dir</code> to $PATH.</td></tr><tr><td><ahref=#prompt>prompt(str, typ)</a></td><td>Changes the shell prompt to the provided string.</td></tr><tr><td><ahref=#read>read(prompt) -> input (string)</a></td><td>Read input from the user, using Hilbish’s line editor/input reader.</td></tr><tr><td><ahref=#run>run(cmd, returnOut) -> exitCode (number), stdout (string), stderr (string)</a></td><td>Runs <code>cmd</code> in Hilbish’s shell script interpreter.</td></tr><tr><td><ahref=#runnerMode>runnerMode(mode)</a></td><td>Sets the execution/runner mode for interactive Hilbish.</td></tr><tr><td><ahref=#timeout>timeout(cb, time) -> @Timer</a></td><td>Executed the <code>cb</code> function after a period of <code>time</code>.</td></tr><tr><td><ahref=#which>which(name) -> string</a></td><td>Checks if <code>name</code> is a valid command.</td></tr></tbody></table><h3id=static-module-fieldsclass=heading>Static module fields
<ahref=#static-module-fieldsclass=heading-link><iclass="fas fa-paperclip"></i></a></h3><table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td>ver</td><td>The version of Hilbish</td></tr><tr><td>goVersion</td><td>The version of Go that Hilbish was compiled with</td></tr><tr><td>user</td><td>Username of the user</td></tr><tr><td>host</td><td>Hostname of the machine</td></tr><tr><td>dataDir</td><td>Directory for Hilbish data files, including the docs and default modules</td></tr><tr><td>interactive</td><td>Is Hilbish in an interactive shell?</td></tr><tr><td>login</td><td>Is Hilbish the login shell?</td></tr><tr><td>vimMode</td><td>Current Vim input mode of Hilbish (will be nil if not in Vim input mode)</td></tr><tr><td>exitCode</td><td>Exit code of the last executed command</td></tr></tbody></table><hr><divid=alias><h4class=heading>hilbish.alias(cmd, orig)
<ahref=#aliasclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Sets an alias, with a name of <code>cmd</code> to another command.</p><h5id=parametersclass=heading>Parameters
<ahref=#parametersclass=heading-link><iclass="fas fa-paperclip"></i></a></h5><p><code>string</code><strong><code>cmd</code></strong><br>Name of the alias</p><p><code>string</code><strong><code>orig</code></strong><br>Command that will be aliased</p><h5id=exampleclass=heading>Example
<ahref=#exampleclass=heading-link><iclass="fas fa-paperclip"></i></a></h5><divclass=highlight><pretabindex=0class=chroma><codeclass=language-luadata-lang=lua><spanclass=line><spanclass=ln>1</span><spanclass=cl><spanclass=c1>-- With this, "ga file" will turn into "git add file"</span>
</span></span><spanclass=line><spanclass=ln>6</span><spanclass=cl><spanclass=c1>-- "dircount ~" would count how many files are in ~ (home directory).</span>
<ahref=#appendPathclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Appends the provided dir to the command path (<code>$PATH</code>)</p><h5id=parameters-1class=heading>Parameters
<ahref=#parameters-1class=heading-link><iclass="fas fa-paperclip"></i></a></h5><p><code>string|table</code><strong><code>dir</code></strong><br>Directory (or directories) to append to path</p><h5id=example-1class=heading>Example
<ahref=#completeclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Registers a completion handler for the specified scope.<br>A <code>scope</code> is expected to be <code>command.<cmd></code>,<br>replacing <cmd>with the name of the command (for example <code>command.git</code>).<br>The documentation for completions, under Features/Completions or <code>doc completions</code><br>provides more details.</p><h5id=parameters-2class=heading>Parameters
<ahref=#example-2class=heading-link><iclass="fas fa-paperclip"></i></a></h5><divclass=highlight><pretabindex=0class=chroma><codeclass=language-luadata-lang=lua><spanclass=line><spanclass=ln> 1</span><spanclass=cl><spanclass=c1>-- This is a very simple example. Read the full doc for completions for details.</span>
</span></span><spanclass=line><spanclass=ln> 7</span><spanclass=cl><spanclass=n>items</span><spanclass=o>=</span><spanclass=n>comps</span><spanclass=p>,</span><spanclass=c1>-- our list of items to complete</span>
</span></span><spanclass=line><spanclass=ln> 8</span><spanclass=cl><spanclass=n>type</span><spanclass=o>=</span><spanclass=s1>'grid'</span><spanclass=c1>-- what our completions will look like.</span>
<ahref=#cwdclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Returns the current directory of the shell.</p><h5id=parameters-3class=heading>Parameters
<ahref=#parameters-3class=heading-link><iclass="fas fa-paperclip"></i></a></h5><p>This function has no parameters.</p></div><hr><divid=exec><h4class=heading>hilbish.exec(cmd)
<ahref=#execclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Replaces the currently running Hilbish instance with the supplied command.<br>This can be used to do an in-place restart.</p><h5id=parameters-4class=heading>Parameters
<ahref=#goroclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Puts <code>fn</code> in a Goroutine.<br>This can be used to run any function in another thread at the same time as other Lua code.<br><strong>NOTE: THIS FUNCTION MAY CRASH HILBISH IF OUTSIDE VARIABLES ARE ACCESSED.</strong><br><strong>This is a limitation of the Lua runtime.</strong></p><h5id=parameters-5class=heading>Parameters
<ahref=#highlighterclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Line highlighter handler.<br>This is mainly for syntax highlighting, but in reality could set the input<br>of the prompt to <em>display</em> anything. The callback is passed the current line<br>and is expected to return a line that will be used as the input display.<br>Note that to set a highlighter, one has to override this function.</p><h5id=parameters-6class=heading>Parameters
<ahref=#example-3class=heading-link><iclass="fas fa-paperclip"></i></a></h5><divclass=highlight><pretabindex=0class=chroma><codeclass=language-luadata-lang=lua><spanclass=line><spanclass=ln>1</span><spanclass=cl><spanclass=c1>--This code will highlight all double quoted strings in green.</span>
<ahref=#hinterclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>The command line hint handler. It gets called on every key insert to<br>determine what text to use as an inline hint. It is passed the current<br>line and cursor position. It is expected to return a string which is used<br>as the text for the hint. This is by default a shim. To set hints,<br>override this function with your custom handler.</p><h5id=parameters-7class=heading>Parameters
<ahref=#parameters-7class=heading-link><iclass="fas fa-paperclip"></i></a></h5><p><code>string</code><strong><code>line</code></strong></p><p><code>number</code><strong><code>pos</code></strong><br>Position of cursor in line. Usually equals string.len(line)</p><h5id=example-4class=heading>Example
<ahref=#example-4class=heading-link><iclass="fas fa-paperclip"></i></a></h5><divclass=highlight><pretabindex=0class=chroma><codeclass=language-luadata-lang=lua><spanclass=line><spanclass=ln>1</span><spanclass=cl><spanclass=c1>-- this will display "hi" after the cursor in a dimmed color.</span>
<ahref=#inputModeclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Sets the input mode for Hilbish’s line reader.<br><code>emacs</code> is the default. Setting it to <code>vim</code> changes behavior of input to be<br>Vim-like with modes and Vim keybinds.</p><h5id=parameters-8class=heading>Parameters
<ahref=#parameters-8class=heading-link><iclass="fas fa-paperclip"></i></a></h5><p><code>string</code><strong><code>mode</code></strong><br>Can be set to either <code>emacs</code> or <code>vim</code></p></div><hr><divid=interval><h4class=heading>hilbish.interval(cb, time) -> <ahref=/Hilbish/docs/api/hilbish/hilbish.timers/#timerstyle=text-decoration:noneid=lol>Timer</a>
<ahref=#intervalclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Runs the <code>cb</code> function every specified amount of <code>time</code>.<br>This creates a timer that ticking immediately.</p><h5id=parameters-9class=heading>Parameters
<ahref=#parameters-9class=heading-link><iclass="fas fa-paperclip"></i></a></h5><p><code>function</code><strong><code>cb</code></strong></p><p><code>number</code><strong><code>time</code></strong><br>Time in milliseconds.</p></div><hr><divid=multiprompt><h4class=heading>hilbish.multiprompt(str)
<ahref=#multipromptclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Changes the text prompt when Hilbish asks for more input.<br>This will show up when text is incomplete, like a missing quote</p><h5id=parameters-10class=heading>Parameters
</span></span></span><spanclass=line><spanclass=ln> 5</span><spanclass=cl><spanclass=cm>but there's a missing quote! hilbish will now prompt you so the terminal
<ahref=#prependPathclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Prepends <code>dir</code> to $PATH.</p><h5id=parameters-11class=heading>Parameters
<ahref=#promptclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Changes the shell prompt to the provided string.<br>There are a few verbs that can be used in the prompt text.<br>These will be formatted and replaced with the appropriate values.<br><code>%d</code> - Current working directory<br><code>%u</code> - Name of current user<br><code>%h</code> - Hostname of device</p><h5id=parameters-12class=heading>Parameters
<ahref=#parameters-12class=heading-link><iclass="fas fa-paperclip"></i></a></h5><p><code>string</code><strong><code>str</code></strong></p><p><code>string</code><strong><code>typ?</code></strong><br>Type of prompt, being left or right. Left by default.</p><h5id=example-6class=heading>Example
<ahref=#example-6class=heading-link><iclass="fas fa-paperclip"></i></a></h5><divclass=highlight><pretabindex=0class=chroma><codeclass=language-luadata-lang=lua><spanclass=line><spanclass=ln>1</span><spanclass=cl><spanclass=c1>-- the default hilbish prompt without color</span>
<ahref=#readclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Read input from the user, using Hilbish’s line editor/input reader.<br>This is a separate instance from the one Hilbish actually uses.<br>Returns <code>input</code>, will be nil if Ctrl-D is pressed, or an error occurs.</p><h5id=parameters-13class=heading>Parameters
<ahref=#parameters-13class=heading-link><iclass="fas fa-paperclip"></i></a></h5><p><code>string</code><strong><code>prompt?</code></strong><br>Text to print before input, can be empty.</p></div><hr><divid=run><h4class=heading>hilbish.run(cmd, returnOut) -> exitCode (number), stdout (string), stderr (string)
<ahref=#runclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Runs <code>cmd</code> in Hilbish’s shell script interpreter.</p><h5id=parameters-14class=heading>Parameters
<ahref=#parameters-14class=heading-link><iclass="fas fa-paperclip"></i></a></h5><p><code>string</code><strong><code>cmd</code></strong></p><p><code>boolean</code><strong><code>returnOut</code></strong><br>If this is true, the function will return the standard output and error of the command instead of printing it.</p></div><hr><divid=runnerMode><h4class=heading>hilbish.runnerMode(mode)
<ahref=#runnerModeclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Sets the execution/runner mode for interactive Hilbish.<br>This determines whether Hilbish wll try to run input as Lua<br>and/or sh or only do one of either.<br>Accepted values for mode are hybrid (the default), hybridRev (sh first then Lua),<br>sh, and lua. It also accepts a function, to which if it is passed one<br>will call it to execute user input instead.<br>Read <ahref=../features/runner-mode>about runner mode</a>
for more information.</p><h5id=parameters-15class=heading>Parameters
<ahref=#timeoutclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Executed the <code>cb</code> function after a period of <code>time</code>.<br>This creates a Timer that starts ticking immediately.</p><h5id=parameters-16class=heading>Parameters
<ahref=#parameters-16class=heading-link><iclass="fas fa-paperclip"></i></a></h5><p><code>function</code><strong><code>cb</code></strong></p><p><code>number</code><strong><code>time</code></strong><br>Time to run in milliseconds.</p></div><hr><divid=which><h4class=heading>hilbish.which(name) -> string
<ahref=#whichclass=heading-link><iclass="fas fa-paperclip"></i></a></h4><p>Checks if <code>name</code> is a valid command.<br>Will return the path of the binary, or a basename if it’s a commander.</p><h5id=parameters-17class=heading>Parameters
<ahref=#autoflushautoclass=heading-link><iclass="fas fa-paperclip"></i></a></h5><p>Sets/toggles the option of automatically flushing output.
A call with no argument will toggle the value.</p><h5id=flushclass=heading>flush()
<ahref=#flushclass=heading-link><iclass="fas fa-paperclip"></i></a></h5><p>Flush writes all buffered input to the sink.</p><h5id=read---stringclass=heading>read() -> string
<ahref=#read---stringclass=heading-link><iclass="fas fa-paperclip"></i></a></h5><p>Reads a liine of input from the sink.</p><h5id=readall---stringclass=heading>readAll() -> string
<ahref=#readall---stringclass=heading-link><iclass="fas fa-paperclip"></i></a></h5><p>Reads all input from the sink.</p><h5id=writestrclass=heading>write(str)