Compare commits

...

8 Commits

20 changed files with 161 additions and 64 deletions

View File

@ -41,6 +41,6 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }} goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }} goarch: ${{ matrix.goarch }}
build_command: task ldflags: '-s -w'
binary_name: hilbish binary_name: hilbish
extra_files: LICENSE README.md CHANGELOG.md .hilbishrc.lua nature libs docs emmyLuaDocs extra_files: LICENSE README.md CHANGELOG.md .hilbishrc.lua nature libs docs emmyLuaDocs

View File

@ -92,8 +92,9 @@ func (a *aliasModule) Loader(rtm *rt.Runtime) *rt.Table {
func _hlalias() {} func _hlalias() {}
// #interface aliases // #interface aliases
// list() // list() -> aliases (table)
// Get a table of all aliases. // Get a table of all aliases, with string keys as the alias and the value as the command.
// @returns table<string, string>
func (a *aliasModule) luaList(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (a *aliasModule) luaList(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
aliasesList := rt.NewTable() aliasesList := rt.NewTable()
for k, v := range a.All() { for k, v := range a.All() {
@ -121,9 +122,10 @@ func (a *aliasModule) luaDelete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// #interface aliases // #interface aliases
// resolve(alias) // resolve(alias) -> command (string)
// Tries to resolve an alias to its command. // Tries to resolve an alias to its command.
// --- @param alias string // --- @param alias string
// --- @returns string
func (a *aliasModule) luaResolve(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (a *aliasModule) luaResolve(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err

16
api.go
View File

@ -184,11 +184,13 @@ func unsetVimMode() {
util.SetField(l, hshMod, "vimMode", rt.NilValue) util.SetField(l, hshMod, "vimMode", rt.NilValue)
} }
// run(cmd, returnOut) -> exitCode, stdout, stderr // run(cmd, returnOut) -> exitCode (number), stdout (string), stderr (string)
// Runs `cmd` in Hilbish's sh interpreter. // Runs `cmd` in Hilbish's sh interpreter.
// If returnOut is true, the outputs of `cmd` will be returned as the 2nd and // If returnOut is true, the outputs of `cmd` will be returned as the 2nd and
// 3rd values instead of being outputted to the terminal. // 3rd values instead of being outputted to the terminal.
// --- @param cmd string // --- @param cmd string
// --- @param returnOut boolean
// --- @returns number, string, string
func hlrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func hlrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
@ -238,11 +240,11 @@ func hlcwd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// read(prompt) -> input // read(prompt) -> input (string)
// Read input from the user, using Hilbish's line editor/input reader. // Read input from the user, using Hilbish's line editor/input reader.
// This is a separate instance from the one Hilbish actually uses. // This is a separate instance from the one Hilbish actually uses.
// Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen) // Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
// --- @param prompt string|nil // --- @param prompt? string
// --- @returns string|nil // --- @returns string|nil
func hlread(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func hlread(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
luaprompt := c.Arg(0) luaprompt := c.Arg(0)
@ -278,7 +280,7 @@ These will be formatted and replaced with the appropriate values.
`%u` - Name of current user `%u` - Name of current user
`%h` - Hostname of device `%h` - Hostname of device
--- @param str string --- @param str string
--- @param typ string|nil Type of prompt, being left or right. Left by default. --- @param typ? string Type of prompt, being left or right. Left by default.
*/ */
func hlprompt(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func hlprompt(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
err := c.Check1Arg() err := c.Check1Arg()
@ -447,7 +449,7 @@ func hlgoro(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// Returns a `timer` object (see `doc timers`). // Returns a `timer` object (see `doc timers`).
// --- @param cb function // --- @param cb function
// --- @param time number // --- @param time number
// --- @return table // --- @returns table
func hltimeout(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func hltimeout(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.CheckNArgs(2); err != nil { if err := c.CheckNArgs(2); err != nil {
return nil, err return nil, err
@ -536,7 +538,7 @@ func hlprependPath(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// which(name) // which(name)
// Checks if `name` is a valid command // Checks if `name` is a valid command
// --- @param binName string // --- @param name string
func hlwhich(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func hlwhich(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
@ -621,7 +623,7 @@ func hlrunnerMode(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// as the text for the hint. This is by default a shim. To set hints, // as the text for the hint. This is by default a shim. To set hints,
// override this function with your custom handler. // override this function with your custom handler.
// --- @param line string // --- @param line string
// --- @param pos int // --- @param pos number
func hlhinter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func hlhinter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.Next(), nil return c.Next(), nil
} }

View File

@ -193,6 +193,8 @@ func completionLoader(rtm *rt.Runtime) *rt.Table {
// handler(line, pos) // handler(line, pos)
// The handler function is the callback for tab completion in Hilbish. // The handler function is the callback for tab completion in Hilbish.
// You can check the completions doc for more info. // You can check the completions doc for more info.
// --- @param line string
// --- @param pos string
func completionHandler(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func completionHandler(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.Next(), nil return c.Next(), nil
} }
@ -202,6 +204,10 @@ func completionHandler(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// Calls a completer function. This is mainly used to call // Calls a completer function. This is mainly used to call
// a command completer, which will have a `name` in the form // a command completer, which will have a `name` in the form
// of `command.name`, example: `command.git` // of `command.name`, example: `command.git`
// --- @param name string
// --- @param query string
// --- @param ctx string
// --- @param fields table
func callLuaCompleter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func callLuaCompleter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.CheckNArgs(4); err != nil { if err := c.CheckNArgs(4); err != nil {
return nil, err return nil, err
@ -244,6 +250,9 @@ func callLuaCompleter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// #interface completions // #interface completions
// files(query, ctx, fields) // files(query, ctx, fields)
// Returns file completion candidates based on the provided query. // Returns file completion candidates based on the provided query.
// --- @param query string
// --- @param ctx string
// --- @param fields table
func luaFileComplete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func luaFileComplete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
query, ctx, fds, err := getCompleteParams(t, c) query, ctx, fds, err := getCompleteParams(t, c)
if err != nil { if err != nil {
@ -263,6 +272,9 @@ func luaFileComplete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// #interface completions // #interface completions
// bins(query, ctx, fields) // bins(query, ctx, fields)
// Returns binary/executale completion candidates based on the provided query. // Returns binary/executale completion candidates based on the provided query.
// --- @param query string
// --- @param ctx string
// --- @param fields table
func luaBinaryComplete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func luaBinaryComplete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
query, ctx, fds, err := getCompleteParams(t, c) query, ctx, fds, err := getCompleteParams(t, c)
if err != nil { if err != nil {

View File

@ -21,8 +21,8 @@ Catches a hook with `name`. Runs the `cb` when it is thrown
### catchOnce(name, cb) ### catchOnce(name, cb)
Same as catch, but only runs the `cb` once and then removes the hook Same as catch, but only runs the `cb` once and then removes the hook
### hooks(name) -> {cb, cb...} ### hooks(name) -> {}
Returns a table with hooks on the event with `name`. Returns a table with hooks (callback functions) on the event with `name`.
### release(name, catcher) ### release(name, catcher)
Removes the `catcher` for the event with `name` Removes the `catcher` for the event with `name`

View File

@ -31,16 +31,21 @@ filepath.Dir
Glob all files and directories that match the pattern. Glob all files and directories that match the pattern.
For the rules, see Go's filepath.Glob For the rules, see Go's filepath.Glob
### join(paths...) ### join(...)
Takes paths and joins them together with the OS's Takes paths and joins them together with the OS's
directory separator (forward or backward slash). directory separator (forward or backward slash).
### mkdir(name, recursive) ### mkdir(name, recursive)
Makes a directory called `name`. If `recursive` is true, it will create its parent directories. Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
### readdir(dir) ### readdir(dir) -> {}
Returns a table of files in `dir` Returns a table of files in `dir`.
### stat(path) ### stat(path) -> {}
Returns info about `path` Returns a table of info about the `path`.
It contains the following keys:
name (string) - Name of the path
size (number) - Size of the path
mode (string) - Permission mode in an octal format string (with leading 0)
isDir (boolean) - If the path is a directory

View File

@ -78,12 +78,12 @@ These will be formatted and replaced with the appropriate values.
`%u` - Name of current user `%u` - Name of current user
`%h` - Hostname of device `%h` - Hostname of device
### read(prompt) -> input ### read(prompt) -> input (string)
Read input from the user, using Hilbish's line editor/input reader. Read input from the user, using Hilbish's line editor/input reader.
This is a separate instance from the one Hilbish actually uses. This is a separate instance from the one Hilbish actually uses.
Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen) Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
### run(cmd, returnOut) -> exitCode, stdout, stderr ### run(cmd, returnOut) -> exitCode (number), stdout (string), stderr (string)
Runs `cmd` in Hilbish's sh interpreter. Runs `cmd` in Hilbish's sh interpreter.
If returnOut is true, the outputs of `cmd` will be returned as the 2nd and If returnOut is true, the outputs of `cmd` will be returned as the 2nd and
3rd values instead of being outputted to the terminal. 3rd values instead of being outputted to the terminal.

View File

@ -17,9 +17,10 @@ This is an alias (ha) for the `hilbish.alias` function.
### delete(name) ### delete(name)
Removes an alias. Removes an alias.
### list() ### list() -> aliases (table)
Get a table of all aliases. Get a table of all aliases, with string keys as the alias and the value as the command.
@returns table<string, string>
### resolve(alias) ### resolve(alias) -> command (string)
Tries to resolve an alias to its command. Tries to resolve an alias to its command.

View File

@ -40,15 +40,15 @@ Stops the job from running.
### add(cmdstr, args, execPath) ### add(cmdstr, args, execPath)
Adds a new job to the job table. Note that this does not immediately run it. Adds a new job to the job table. Note that this does not immediately run it.
### all() ### all() -> jobs (table<Job/Table>)
Returns a table of all job objects. Returns a table of all job objects.
### disown(id) ### disown(id)
Disowns a job. This deletes it from the job table. Disowns a job. This deletes it from the job table.
### get(id) ### get(id) -> job (Job/Table)
Get a job object via its ID. Get a job object via its ID.
### last() -> Job ### last() -> job (Job/Table)
Returns the last added job from the table. Returns the last added job from the table.

View File

@ -12,6 +12,10 @@ The timers interface si one to easily set timeouts and intervals
to run functions after a certain time or repeatedly without using to run functions after a certain time or repeatedly without using
odd tricks. odd tricks.
## Interface fields
- `INTERVAL`: Constant for an interval timer type
- `TIMEOUT`: Constant for a timeout timer type
## Object properties ## Object properties
- `type`: What type of timer it is - `type`: What type of timer it is
- `running`: If the timer is running - `running`: If the timer is running
@ -26,8 +30,8 @@ Stops a timer.
### create(type, time, callback) ### create(type, time, callback)
Creates a timer that runs based on the specified `time` in milliseconds. Creates a timer that runs based on the specified `time` in milliseconds.
The `type` can either be interval (value of 0) or timeout (value of 1). The `type` can either be `hilbish.timers.INTERVAL` or `hilbish.timers.TIMEOUT`
### get(id) ### get(id) -> timer (Timer/Table)
Retrieves a timer via its ID. Retrieves a timer via its ID.

View File

@ -45,6 +45,8 @@ func editorInsert(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// #interface editor // #interface editor
// setVimRegister(register, text) // setVimRegister(register, text)
// Sets the vim register at `register` to hold the passed text. // Sets the vim register at `register` to hold the passed text.
// --- @param register string
// --- @param text string
func editorSetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func editorSetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
@ -68,6 +70,7 @@ func editorSetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// #interface editor // #interface editor
// getVimRegister(register) // getVimRegister(register)
// Returns the text that is at the register. // Returns the text that is at the register.
// --- @param register string
func editorGetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func editorGetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err

View File

@ -12,9 +12,9 @@ function bait.catch(name, cb) end
--- @param cb function --- @param cb function
function bait.catchOnce(name, cb) end function bait.catchOnce(name, cb) end
--- Returns a table with hooks on the event with `name`. --- Returns a table with hooks (callback functions) on the event with `name`.
--- @param name string --- @param name string
--- @returns table --- @returns table<function>
function bait.hooks(name) end function bait.hooks(name) end
--- Removes the `catcher` for the event with `name` --- Removes the `catcher` for the event with `name`

View File

@ -16,28 +16,37 @@ function fs.cd(dir) end
--- Returns the directory part of `path`. For the rules, see Go's --- Returns the directory part of `path`. For the rules, see Go's
--- filepath.Dir --- filepath.Dir
--- @param path string
function fs.dir(path) end function fs.dir(path) end
--- Glob all files and directories that match the pattern. --- Glob all files and directories that match the pattern.
--- For the rules, see Go's filepath.Glob --- For the rules, see Go's filepath.Glob
--- @param pattern string
function fs.glob(pattern) end function fs.glob(pattern) end
--- Takes paths and joins them together with the OS's --- Takes paths and joins them together with the OS's
--- directory separator (forward or backward slash). --- directory separator (forward or backward slash).
function fs.join(paths...) end --- @vararg any
function fs.join(...) end
--- Makes a directory called `name`. If `recursive` is true, it will create its parent directories. --- Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
--- @param name string --- @param name string
--- @param recursive boolean --- @param recursive boolean
function fs.mkdir(name, recursive) end function fs.mkdir(name, recursive) end
--- Returns a table of files in `dir` --- Returns a table of files in `dir`.
--- @param dir string --- @param dir string
--- @return table --- @return table
function fs.readdir(dir) end function fs.readdir(dir) end
--- Returns info about `path` --- Returns a table of info about the `path`.
--- It contains the following keys:
--- name (string) - Name of the path
--- size (number) - Size of the path
--- mode (string) - Permission mode in an octal format string (with leading 0)
--- isDir (boolean) - If the path is a directory
--- @param path string --- @param path string
--- @returns table
function fs.stat(path) end function fs.stat(path) end
return fs return fs

View File

@ -11,27 +11,37 @@ function hilbish.aliases.add(alias, cmd) end
--- which will be used to execute all interactive input. --- which will be used to execute all interactive input.
--- In normal cases, neither callbacks should be overrided by the user, --- In normal cases, neither callbacks should be overrided by the user,
--- as the higher level functions listed below this will handle it. --- as the higher level functions listed below this will handle it.
--- @param cb function
function hilbish.runner.setMode(cb) end function hilbish.runner.setMode(cb) end
--- Calls a completer function. This is mainly used to call --- Calls a completer function. This is mainly used to call
--- a command completer, which will have a `name` in the form --- a command completer, which will have a `name` in the form
--- of `command.name`, example: `command.git` --- of `command.name`, example: `command.git`
--- @param name string
--- @param query string
--- @param ctx string
--- @param fields table
function hilbish.completions.call(name, query, ctx, fields) end function hilbish.completions.call(name, query, ctx, fields) end
--- The handler function is the callback for tab completion in Hilbish. --- The handler function is the callback for tab completion in Hilbish.
--- You can check the completions doc for more info. --- You can check the completions doc for more info.
--- @param line string
--- @param pos string
function hilbish.completions.handler(line, pos) end function hilbish.completions.handler(line, pos) end
--- Returns the current input line. --- Returns the current input line.
function hilbish.editor.getLine() end function hilbish.editor.getLine() end
--- Returns the text that is at the register. --- Returns the text that is at the register.
--- @param register string
function hilbish.editor.getVimRegister(register) end function hilbish.editor.getVimRegister(register) end
--- Inserts text into the line. --- Inserts text into the line.
function hilbish.editor.insert(text) end function hilbish.editor.insert(text) end
--- Sets the vim register at `register` to hold the passed text. --- Sets the vim register at `register` to hold the passed text.
--- @param register string
--- @param text string
function hilbish.editor.setVimRegister(register, text) end function hilbish.editor.setVimRegister(register, text) end
--- Sets an alias of `cmd` to `orig` --- Sets an alias of `cmd` to `orig`
@ -76,7 +86,7 @@ function hilbish.highlighter(line) end
--- as the text for the hint. This is by default a shim. To set hints, --- as the text for the hint. This is by default a shim. To set hints,
--- override this function with your custom handler. --- override this function with your custom handler.
--- @param line string --- @param line string
--- @param pos int --- @param pos number
function hilbish.hinter(line, pos) end function hilbish.hinter(line, pos) end
--- Sets the input mode for Hilbish's line reader. Accepts either emacs or vim --- Sets the input mode for Hilbish's line reader. Accepts either emacs or vim
@ -105,13 +115,13 @@ function hilbish.prependPath(dir) end
--- `%u` - Name of current user --- `%u` - Name of current user
--- `%h` - Hostname of device --- `%h` - Hostname of device
--- @param str string --- @param str string
--- @param typ string|nil Type of prompt, being left or right. Left by default. --- @param typ? string Type of prompt, being left or right. Left by default.
function hilbish.prompt(str, typ) end function hilbish.prompt(str, typ) end
--- Read input from the user, using Hilbish's line editor/input reader. --- Read input from the user, using Hilbish's line editor/input reader.
--- This is a separate instance from the one Hilbish actually uses. --- This is a separate instance from the one Hilbish actually uses.
--- Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen) --- Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
--- @param prompt string|nil --- @param prompt? string
--- @returns string|nil --- @returns string|nil
function hilbish.read(prompt) end function hilbish.read(prompt) end
@ -119,6 +129,8 @@ function hilbish.read(prompt) end
--- If returnOut is true, the outputs of `cmd` will be returned as the 2nd and --- If returnOut is true, the outputs of `cmd` will be returned as the 2nd and
--- 3rd values instead of being outputted to the terminal. --- 3rd values instead of being outputted to the terminal.
--- @param cmd string --- @param cmd string
--- @param returnOut boolean
--- @returns number, string, string
function hilbish.run(cmd, returnOut) end function hilbish.run(cmd, returnOut) end
--- Sets the execution/runner mode for interactive Hilbish. This determines whether --- Sets the execution/runner mode for interactive Hilbish. This determines whether
@ -133,20 +145,26 @@ function hilbish.runnerMode(mode) end
--- Returns a `timer` object (see `doc timers`). --- Returns a `timer` object (see `doc timers`).
--- @param cb function --- @param cb function
--- @param time number --- @param time number
--- @return table --- @returns table
function hilbish.timeout(cb, time) end function hilbish.timeout(cb, time) end
--- Checks if `name` is a valid command --- Checks if `name` is a valid command
--- @param binName string --- @param name string
function hilbish.which(name) end function hilbish.which(name) end
--- Puts a job in the background. This acts the same as initially running a job. --- Puts a job in the background. This acts the same as initially running a job.
function hilbish.jobs:background() end function hilbish.jobs:background() end
--- Returns binary/executale completion candidates based on the provided query. --- Returns binary/executale completion candidates based on the provided query.
--- @param query string
--- @param ctx string
--- @param fields table
function hilbish.completions.bins(query, ctx, fields) end function hilbish.completions.bins(query, ctx, fields) end
--- Returns file completion candidates based on the provided query. --- Returns file completion candidates based on the provided query.
--- @param query string
--- @param ctx string
--- @param fields table
function hilbish.completions.files(query, ctx, fields) end function hilbish.completions.files(query, ctx, fields) end
--- Puts a job in the foreground. This will cause it to run like it was --- Puts a job in the foreground. This will cause it to run like it was
@ -155,6 +173,7 @@ function hilbish.jobs:foreground() end
--- Evaluates `cmd` as Lua input. This is the same as using `dofile` --- Evaluates `cmd` as Lua input. This is the same as using `dofile`
--- or `load`, but is appropriated for the runner interface. --- or `load`, but is appropriated for the runner interface.
--- @param cmd string
function hilbish.runner.lua(cmd) end function hilbish.runner.lua(cmd) end
--- Starts running the job. --- Starts running the job.
@ -165,6 +184,7 @@ function hilbish.jobs.stop() end
--- Runs a command in Hilbish's shell script interpreter. --- Runs a command in Hilbish's shell script interpreter.
--- This is the equivalent of using `source`. --- This is the equivalent of using `source`.
--- @param cmd string
function hilbish.runner.sh(cmd) end function hilbish.runner.sh(cmd) end
--- Starts a timer. --- Starts a timer.
@ -177,26 +197,36 @@ function hilbish.timers:stop() end
--- @param name string --- @param name string
function hilbish.aliases.delete(name) end function hilbish.aliases.delete(name) end
--- Get a table of all aliases. --- Get a table of all aliases, with string keys as the alias and the value as the command.
--- @returns table<string, string>
function hilbish.aliases.list() end function hilbish.aliases.list() end
--- Tries to resolve an alias to its command. --- Tries to resolve an alias to its command.
--- @param alias string --- @param alias string
--- @returns string
function hilbish.aliases.resolve(alias) end function hilbish.aliases.resolve(alias) end
--- Adds a new job to the job table. Note that this does not immediately run it. --- Adds a new job to the job table. Note that this does not immediately run it.
--- @param cmdstr string
--- @param args table
--- @param execPath string
function hilbish.jobs.add(cmdstr, args, execPath) end function hilbish.jobs.add(cmdstr, args, execPath) end
--- Returns a table of all job objects. --- Returns a table of all job objects.
--- @returns table<Job>
function hilbish.jobs.all() end function hilbish.jobs.all() end
--- Disowns a job. This deletes it from the job table. --- Disowns a job. This deletes it from the job table.
--- @param id number
function hilbish.jobs.disown(id) end function hilbish.jobs.disown(id) end
--- Get a job object via its ID. --- Get a job object via its ID.
--- @param id number
--- @returns Job
function hilbish.jobs.get(id) end function hilbish.jobs.get(id) end
--- Returns the last added job from the table. --- Returns the last added job from the table.
--- @returns Job
function hilbish.jobs.last() end function hilbish.jobs.last() end
--- Adds a command to the history. --- Adds a command to the history.
@ -215,10 +245,15 @@ function hilbish.history.get(idx) end
function hilbish.history.size() end function hilbish.history.size() end
--- Creates a timer that runs based on the specified `time` in milliseconds. --- Creates a timer that runs based on the specified `time` in milliseconds.
--- The `type` can either be interval (value of 0) or timeout (value of 1). --- The `type` can either be `hilbish.timers.INTERVAL` or `hilbish.timers.TIMEOUT`
--- @param type number
--- @param time number
--- @param callback function
function hilbish.timers.create(type, time, callback) end function hilbish.timers.create(type, time, callback) end
--- Retrieves a timer via its ID. --- Retrieves a timer via its ID.
--- @param id number
--- @returns Timer
function hilbish.timers.get(id) end function hilbish.timers.get(id) end
return hilbish return hilbish

View File

@ -296,10 +296,10 @@ func (b *Bait) brelease(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.Next(), nil return c.Next(), nil
} }
// hooks(name) -> {cb, cb...} // hooks(name) -> {}
// Returns a table with hooks on the event with `name`. // Returns a table with hooks (callback functions) on the event with `name`.
// --- @param name string // --- @param name string
// --- @returns table // --- @returns table<function>
func (b *Bait) bhooks(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (b *Bait) bhooks(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err

View File

@ -93,9 +93,15 @@ func fmkdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.Next(), err return c.Next(), err
} }
// stat(path) // stat(path) -> {}
// Returns info about `path` // Returns a table of info about the `path`.
// It contains the following keys:
// name (string) - Name of the path
// size (number) - Size of the path
// mode (string) - Permission mode in an octal format string (with leading 0)
// isDir (boolean) - If the path is a directory
// --- @param path string // --- @param path string
// --- @returns table
func fstat(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func fstat(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
@ -119,8 +125,8 @@ func fstat(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.PushingNext1(t.Runtime, rt.TableValue(statTbl)), nil return c.PushingNext1(t.Runtime, rt.TableValue(statTbl)), nil
} }
// readdir(dir) // readdir(dir) -> {}
// Returns a table of files in `dir` // Returns a table of files in `dir`.
// --- @param dir string // --- @param dir string
// --- @return table // --- @return table
func freaddir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func freaddir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
@ -181,6 +187,7 @@ func fbasename(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// dir(path) // dir(path)
// Returns the directory part of `path`. For the rules, see Go's // Returns the directory part of `path`. For the rules, see Go's
// filepath.Dir // filepath.Dir
// --- @param path string
func fdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func fdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
@ -196,6 +203,7 @@ func fdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// glob(pattern) // glob(pattern)
// Glob all files and directories that match the pattern. // Glob all files and directories that match the pattern.
// For the rules, see Go's filepath.Glob // For the rules, see Go's filepath.Glob
// --- @param pattern string
func fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
@ -219,9 +227,10 @@ func fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.PushingNext(t.Runtime, rt.TableValue(luaMatches)), nil return c.PushingNext(t.Runtime, rt.TableValue(luaMatches)), nil
} }
// join(paths...) // join(...)
// Takes paths and joins them together with the OS's // Takes paths and joins them together with the OS's
// directory separator (forward or backward slash). // directory separator (forward or backward slash).
// --- @vararg any
func fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
strs := make([]string, len(c.Etc())) strs := make([]string, len(c.Etc()))
for i, v := range c.Etc() { for i, v := range c.Etc() {

14
job.go
View File

@ -384,8 +384,10 @@ func jobUserData(j *job) *rt.UserData {
} }
// #interface jobs // #interface jobs
// get(id) // get(id) -> job (Job/Table)
// Get a job object via its ID. // Get a job object via its ID.
// --- @param id number
// --- @returns Job
func (j *jobHandler) luaGetJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (j *jobHandler) luaGetJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
j.mu.RLock() j.mu.RLock()
defer j.mu.RUnlock() defer j.mu.RUnlock()
@ -409,6 +411,9 @@ func (j *jobHandler) luaGetJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// #interface jobs // #interface jobs
// add(cmdstr, args, execPath) // add(cmdstr, args, execPath)
// Adds a new job to the job table. Note that this does not immediately run it. // Adds a new job to the job table. Note that this does not immediately run it.
// --- @param cmdstr string
// --- @param args table
// --- @param execPath string
func (j *jobHandler) luaAddJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (j *jobHandler) luaAddJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.CheckNArgs(3); err != nil { if err := c.CheckNArgs(3); err != nil {
return nil, err return nil, err
@ -439,8 +444,9 @@ func (j *jobHandler) luaAddJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// #interface jobs // #interface jobs
// all() // all() -> jobs (table<Job/Table>)
// Returns a table of all job objects. // Returns a table of all job objects.
// --- @returns table<Job>
func (j *jobHandler) luaAllJobs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (j *jobHandler) luaAllJobs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
j.mu.RLock() j.mu.RLock()
defer j.mu.RUnlock() defer j.mu.RUnlock()
@ -456,6 +462,7 @@ func (j *jobHandler) luaAllJobs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// #interface jobs // #interface jobs
// disown(id) // disown(id)
// Disowns a job. This deletes it from the job table. // Disowns a job. This deletes it from the job table.
// --- @param id number
func (j *jobHandler) luaDisownJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (j *jobHandler) luaDisownJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
@ -474,8 +481,9 @@ func (j *jobHandler) luaDisownJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// #interface jobs // #interface jobs
// last() -> Job // last() -> job (Job/Table)
// Returns the last added job from the table. // Returns the last added job from the table.
// --- @returns Job
func (j *jobHandler) luaLastJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (j *jobHandler) luaLastJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
j.mu.RLock() j.mu.RLock()
defer j.mu.RUnlock() defer j.mu.RUnlock()

View File

@ -32,12 +32,14 @@ func runnerModeLoader(rtm *rt.Runtime) *rt.Table {
// which will be used to execute all interactive input. // which will be used to execute all interactive input.
// In normal cases, neither callbacks should be overrided by the user, // In normal cases, neither callbacks should be overrided by the user,
// as the higher level functions listed below this will handle it. // as the higher level functions listed below this will handle it.
// --- @param cb function
func _runnerMode() {} func _runnerMode() {}
// #interface runner // #interface runner
// sh(cmd) // sh(cmd)
// Runs a command in Hilbish's shell script interpreter. // Runs a command in Hilbish's shell script interpreter.
// This is the equivalent of using `source`. // This is the equivalent of using `source`.
// --- @param cmd string
func shRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func shRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
@ -65,6 +67,7 @@ func shRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// lua(cmd) // lua(cmd)
// Evaluates `cmd` as Lua input. This is the same as using `dofile` // Evaluates `cmd` as Lua input. This is the same as using `dofile`
// or `load`, but is appropriated for the runner interface. // or `load`, but is appropriated for the runner interface.
// --- @param cmd string
func luaRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func luaRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err

View File

@ -64,7 +64,10 @@ func (th *timersModule) get(id int) *timer {
// #interface timers // #interface timers
// create(type, time, callback) // create(type, time, callback)
// Creates a timer that runs based on the specified `time` in milliseconds. // Creates a timer that runs based on the specified `time` in milliseconds.
// The `type` can either be interval (value of 0) or timeout (value of 1). // The `type` can either be `hilbish.timers.INTERVAL` or `hilbish.timers.TIMEOUT`
// --- @param type number
// --- @param time number
// --- @param callback function
func (th *timersModule) luaCreate(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (th *timersModule) luaCreate(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.CheckNArgs(3); err != nil { if err := c.CheckNArgs(3); err != nil {
return nil, err return nil, err
@ -88,8 +91,10 @@ func (th *timersModule) luaCreate(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// #interface timers // #interface timers
// get(id) // get(id) -> timer (Timer/Table)
// Retrieves a timer via its ID. // Retrieves a timer via its ID.
// --- @param id number
// --- @returns Timer
func (th *timersModule) luaGet(thr *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (th *timersModule) luaGet(thr *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
@ -108,6 +113,8 @@ func (th *timersModule) luaGet(thr *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// #interface timers // #interface timers
// #field INTERVAL Constant for an interval timer type
// #field TIMEOUT Constant for a timeout timer type
// #property type What type of timer it is // #property type What type of timer it is
// #property running If the timer is running // #property running If the timer is running
// #property duration The duration in milliseconds that the timer will run // #property duration The duration in milliseconds that the timer will run
@ -156,6 +163,9 @@ func (th *timersModule) loader(rtm *rt.Runtime) *rt.Table {
luaTh := rt.NewTable() luaTh := rt.NewTable()
util.SetExports(rtm, luaTh, thExports) util.SetExports(rtm, luaTh, thExports)
util.SetField(rtm, luaTh, "INTERVAL", rt.IntValue(0))
util.SetField(rtm, luaTh, "TIMEOUT", rt.IntValue(1))
return luaTh return luaTh
} }

View File

@ -5,15 +5,9 @@ weight: -1
menu: docs menu: docs
--- ---
Here lies the documentation for Hilbish, the hyper extensible Lua shell. Hilbish is a hyper-extensible shell mainly intended for interactive use.
Hilbish provides you with a few quality of life features and useful To enhance the interactive experience, Hilbish comes with a wide range
functions to ensure you can make the shell fully yours. of features and sane defaults, including a nice looking prompt,
advanced completion menus and history search.
These features include: Here documents some of the features of Hilbish and the Lua API.
- Completion and history search menus
- Hinting and syntax highlighting (scripted by user)
# Installation
Steps on installing Hilbish will be at the Install page in the navigation bar
at the top. This also included getting development builds from the GitHub
repository.