mirror of https://github.com/Hilbis/Hilbish
Compare commits
4 Commits
bb8d072b8c
...
f40ce3c8f7
Author | SHA1 | Date |
---|---|---|
sammyette | f40ce3c8f7 | |
sammyette | be526c15d1 | |
sammyette | 393b2009bf | |
sammyette | 77979dca19 |
|
@ -555,7 +555,7 @@ func main() {
|
||||||
`, htmlSig, dps.FuncName))
|
`, htmlSig, dps.FuncName))
|
||||||
for _, doc := range dps.Doc {
|
for _, doc := range dps.Doc {
|
||||||
if !strings.HasPrefix(doc, "---") {
|
if !strings.HasPrefix(doc, "---") {
|
||||||
f.WriteString(doc + "\n")
|
f.WriteString(doc + " \n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.WriteString("#### Parameters\n")
|
f.WriteString("#### Parameters\n")
|
||||||
|
|
|
@ -49,9 +49,9 @@ bait.catch(name, cb)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Catches an event. This function can be used to act on events.
|
Catches an event. This function can be used to act on events.
|
||||||
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
`string` **`name`**
|
`string` **`name`**
|
||||||
The name of the hook.
|
The name of the hook.
|
||||||
|
@ -75,7 +75,7 @@ bait.catchOnce(name, cb)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Catches an event, but only once. This will remove the hook immediately after it runs for the first time.
|
Catches an event, but only once. This will remove the hook immediately after it runs for the first time.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
`string` **`name`**
|
`string` **`name`**
|
||||||
The name of the event
|
The name of the event
|
||||||
|
@ -93,7 +93,7 @@ bait.hooks(name) -> table
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Returns a list of callbacks that are hooked on an event with the corresponding `name`.
|
Returns a list of callbacks that are hooked on an event with the corresponding `name`.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
`string` **`name`**
|
`string` **`name`**
|
||||||
The name of the function
|
The name of the function
|
||||||
|
@ -108,11 +108,11 @@ bait.release(name, catcher)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Removes the `catcher` for the event with `name`.
|
Removes the `catcher` for the event with `name`.
|
||||||
For this to work, `catcher` has to be the same function used to catch
|
For this to work, `catcher` has to be the same function used to catch
|
||||||
an event, like one saved to a variable.
|
an event, like one saved to a variable.
|
||||||
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
`string` **`name`**
|
`string` **`name`**
|
||||||
Name of the event the hook is on
|
Name of the event the hook is on
|
||||||
|
@ -140,9 +140,9 @@ bait.throw(name, ...args)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Throws a hook with `name` with the provided `args`.
|
Throws a hook with `name` with the provided `args`.
|
||||||
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
`string` **`name`**
|
`string` **`name`**
|
||||||
The name of the hook.
|
The name of the hook.
|
||||||
|
|
|
@ -50,7 +50,7 @@ commander.deregister(name)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Removes the named command. Note that this will only remove Commander-registered commands.
|
Removes the named command. Note that this will only remove Commander-registered commands.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
`string` **`name`**
|
`string` **`name`**
|
||||||
Name of the command to remove.
|
Name of the command to remove.
|
||||||
|
@ -65,10 +65,10 @@ commander.register(name, cb)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Adds a new command with the given `name`. When Hilbish has to run a command with a name,
|
Adds a new command with the given `name`. When Hilbish has to run a command with a name,
|
||||||
it will run the function providing the arguments and sinks.
|
it will run the function providing the arguments and sinks.
|
||||||
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
`string` **`name`**
|
`string` **`name`**
|
||||||
Name of the command
|
Name of the command
|
||||||
|
|
159
docs/api/fs.md
159
docs/api/fs.md
|
@ -8,22 +8,28 @@ menu:
|
||||||
---
|
---
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
The fs module provides easy and simple access to filesystem functions
|
|
||||||
and other things, and acts an addition to the Lua standard library's
|
The fs module provides filesystem functions to Hilbish. While Lua's standard
|
||||||
I/O and filesystem functions.
|
library has some I/O functions, they're missing a lot of the basics. The `fs`
|
||||||
|
library offers more functions and will work on any operating system Hilbish does.
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|||
|
|||
|
||||||
|----|----|
|
|----|----|
|
||||||
|<a href="#abs">abs(path) -> string</a>|Gives an absolute version of `path`.|
|
|<a href="#abs">abs(path) -> string</a>|Returns an absolute version of the `path`.|
|
||||||
|<a href="#basename">basename(path) -> string</a>|Gives the basename of `path`. For the rules,|
|
|<a href="#basename">basename(path) -> string</a>|Returns the "basename," or the last part of the provided `path`. If path is empty,|
|
||||||
|<a href="#cd">cd(dir)</a>|Changes directory to `dir`|
|
|<a href="#cd">cd(dir)</a>|Changes Hilbish's directory to `dir`.|
|
||||||
|<a href="#dir">dir(path) -> string</a>|Returns the directory part of `path`. For the rules, see Go's|
|
|<a href="#dir">dir(path) -> string</a>|Returns the directory part of `path`. If a file path like|
|
||||||
|<a href="#glob">glob(pattern) -> matches (table)</a>|Glob all files and directories that match the pattern.|
|
|<a href="#glob">glob(pattern) -> matches (table)</a>|Match all files based on the provided `pattern`.|
|
||||||
|<a href="#join">join(...) -> string</a>|Takes paths and joins them together with the OS's|
|
|<a href="#join">join(...path) -> string</a>|Takes any list of paths and joins them based on the operating system's path separator.|
|
||||||
|<a href="#mkdir">mkdir(name, recursive)</a>|Makes a directory called `name`. If `recursive` is true, it will create its parent directories.|
|
|<a href="#mkdir">mkdir(name, recursive)</a>|Creates a new directory with the provided `name`.|
|
||||||
|<a href="#readdir">readdir(dir) -> {}</a>|Returns a table of files in `dir`.|
|
|<a href="#readdir">readdir(path) -> table[string]</a>|Returns a list of all files and directories in the provided path.|
|
||||||
|<a href="#stat">stat(path) -> {}</a>|Returns a table of info about the `path`.|
|
|<a href="#stat">stat(path) -> {}</a>|Returns the information about a given `path`.|
|
||||||
|
|
||||||
|
## Static module fields
|
||||||
|
|||
|
||||||
|
|----|----|
|
||||||
|
|pathSep|The operating system's path separator.|
|
||||||
|
|
||||||
<hr><div id='abs'>
|
<hr><div id='abs'>
|
||||||
<h4 class='heading'>
|
<h4 class='heading'>
|
||||||
|
@ -33,9 +39,12 @@ fs.abs(path) -> string
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Gives an absolute version of `path`.
|
Returns an absolute version of the `path`.
|
||||||
|
This can be used to resolve short paths like `..` to `/home/user`.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
`string` **`path`**
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr><div id='basename'>
|
<hr><div id='basename'>
|
||||||
|
@ -46,10 +55,12 @@ fs.basename(path) -> string
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Gives the basename of `path`. For the rules,
|
Returns the "basename," or the last part of the provided `path`. If path is empty,
|
||||||
see Go's filepath.Base
|
`.` will be returned.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
`string` **`path`**
|
||||||
|
Path to get the base name of.
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr><div id='cd'>
|
<hr><div id='cd'>
|
||||||
|
@ -60,9 +71,11 @@ fs.cd(dir)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Changes directory to `dir`
|
Changes Hilbish's directory to `dir`.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
`string` **`dir`**
|
||||||
|
Path to change directory to.
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr><div id='dir'>
|
<hr><div id='dir'>
|
||||||
|
@ -73,10 +86,12 @@ fs.dir(path) -> string
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Returns the directory part of `path`. For the rules, see Go's
|
Returns the directory part of `path`. If a file path like
|
||||||
filepath.Dir
|
`~/Documents/doc.txt` then this function will return `~/Documents`.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
`string` **`path`**
|
||||||
|
Path to get the directory for.
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr><div id='glob'>
|
<hr><div id='glob'>
|
||||||
|
@ -87,24 +102,50 @@ fs.glob(pattern) -> matches (table)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Glob all files and directories that match the pattern.
|
Match all files based on the provided `pattern`.
|
||||||
For the rules, see Go's filepath.Glob
|
For the syntax' refer to Go's filepath.Match function: https://pkg.go.dev/path/filepath#Match
|
||||||
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
`string` **`pattern`**
|
||||||
|
Pattern to compare files with.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```lua
|
||||||
|
--[[
|
||||||
|
Within a folder that contains the following files:
|
||||||
|
a.txt
|
||||||
|
init.lua
|
||||||
|
code.lua
|
||||||
|
doc.pdf
|
||||||
|
]]--
|
||||||
|
local matches = fs.glob './*.lua'
|
||||||
|
print(matches)
|
||||||
|
-- -> {'init.lua', 'code.lua'}
|
||||||
|
````
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr><div id='join'>
|
<hr><div id='join'>
|
||||||
<h4 class='heading'>
|
<h4 class='heading'>
|
||||||
fs.join(...) -> string
|
fs.join(...path) -> string
|
||||||
<a href="#join" class='heading-link'>
|
<a href="#join" class='heading-link'>
|
||||||
<i class="fas fa-paperclip"></i>
|
<i class="fas fa-paperclip"></i>
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Takes paths and joins them together with the OS's
|
Takes any list of paths and joins them based on the operating system's path separator.
|
||||||
directory separator (forward or backward slash).
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
`string` **`path`** (This type is variadic. You can pass an infinite amount of parameters with this type.)
|
||||||
|
Paths to join together
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```lua
|
||||||
|
-- This prints the directory for Hilbish's config!
|
||||||
|
print(fs.join(hilbish.userDir.config, 'hilbish'))
|
||||||
|
-- -> '/home/user/.config/hilbish' on Linux
|
||||||
|
````
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr><div id='mkdir'>
|
<hr><div id='mkdir'>
|
||||||
|
@ -115,22 +156,38 @@ fs.mkdir(name, recursive)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
|
Creates a new directory with the provided `name`.
|
||||||
|
With `recursive`, mkdir will create parent directories.
|
||||||
|
|
||||||
|
-- This will create the directory foo, then create the directory bar in the
|
||||||
|
-- foo directory. If recursive is false in this case, it will fail.
|
||||||
|
fs.mkdir('./foo/bar', true)
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
`string` **`name`**
|
||||||
|
Name of the directory
|
||||||
|
|
||||||
|
`boolean` **`recursive`**
|
||||||
|
Whether to create parent directories for the provided name
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```lua
|
||||||
|
|
||||||
|
````
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr><div id='readdir'>
|
<hr><div id='readdir'>
|
||||||
<h4 class='heading'>
|
<h4 class='heading'>
|
||||||
fs.readdir(dir) -> {}
|
fs.readdir(path) -> table[string]
|
||||||
<a href="#readdir" class='heading-link'>
|
<a href="#readdir" class='heading-link'>
|
||||||
<i class="fas fa-paperclip"></i>
|
<i class="fas fa-paperclip"></i>
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Returns a table of files in `dir`.
|
Returns a list of all files and directories in the provided path.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
`string` **`dir`**
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr><div id='stat'>
|
<hr><div id='stat'>
|
||||||
|
@ -141,13 +198,33 @@ fs.stat(path) -> {}
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Returns a table of info about the `path`.
|
Returns the information about a given `path`.
|
||||||
It contains the following keys:
|
The returned table contains the following values:
|
||||||
name (string) - Name of the path
|
name (string) - Name of the path
|
||||||
size (number) - Size of the path
|
size (number) - Size of the path in bytes
|
||||||
mode (string) - Permission mode in an octal format string (with leading 0)
|
mode (string) - Unix permission mode in an octal format string (with leading 0)
|
||||||
isDir (boolean) - If the path is a directory
|
isDir (boolean) - If the path is a directory
|
||||||
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
`string` **`path`**
|
||||||
|
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```lua
|
||||||
|
local inspect = require 'inspect'
|
||||||
|
|
||||||
|
local stat = fs.stat '~'
|
||||||
|
print(inspect(stat))
|
||||||
|
--[[
|
||||||
|
Would print the following:
|
||||||
|
{
|
||||||
|
isDir = true,
|
||||||
|
mode = "0755",
|
||||||
|
name = "username",
|
||||||
|
size = 12288
|
||||||
|
}
|
||||||
|
]]--
|
||||||
|
````
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ hilbish.alias(cmd, orig)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Sets an alias of `cmd` to `orig`
|
Sets an alias of `cmd` to `orig`
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -67,7 +67,7 @@ hilbish.appendPath(dir)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Appends `dir` to $PATH
|
Appends `dir` to $PATH
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -80,11 +80,11 @@ hilbish.complete(scope, cb)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Registers a completion handler for `scope`.
|
Registers a completion handler for `scope`.
|
||||||
A `scope` is currently only expected to be `command.<cmd>`,
|
A `scope` is currently only expected to be `command.<cmd>`,
|
||||||
replacing <cmd> with the name of the command (for example `command.git`).
|
replacing <cmd> with the name of the command (for example `command.git`).
|
||||||
`cb` must be a function that returns a table of "completion groups."
|
`cb` must be a function that returns a table of "completion groups."
|
||||||
Check `doc completions` for more information.
|
Check `doc completions` for more information.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -97,7 +97,7 @@ hilbish.cwd() -> string
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Returns the current directory of the shell
|
Returns the current directory of the shell
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -110,7 +110,7 @@ hilbish.exec(cmd)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Replaces running hilbish with `cmd`
|
Replaces running hilbish with `cmd`
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -123,7 +123,7 @@ hilbish.goro(fn)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Puts `fn` in a goroutine
|
Puts `fn` in a goroutine
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -136,18 +136,18 @@ hilbish.highlighter(line)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Line highlighter handler. This is mainly for syntax highlighting, but in
|
Line highlighter handler. This is mainly for syntax highlighting, but in
|
||||||
reality could set the input of the prompt to *display* anything. The
|
reality could set the input of the prompt to *display* anything. The
|
||||||
callback is passed the current line and is expected to return a line that
|
callback is passed the current line and is expected to return a line that
|
||||||
will be used as the input display.
|
will be used as the input display.
|
||||||
Note that to set a highlighter, one has to override this function.
|
Note that to set a highlighter, one has to override this function.
|
||||||
Example:
|
Example:
|
||||||
```
|
```
|
||||||
function hilbish.highlighter(line)
|
function hilbish.highlighter(line)
|
||||||
return line:gsub('"%w+"', function(c) return lunacolors.green(c) end)
|
return line:gsub('"%w+"', function(c) return lunacolors.green(c) end)
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
This code will highlight all double quoted strings in green.
|
This code will highlight all double quoted strings in green.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -160,11 +160,11 @@ hilbish.hinter(line, pos)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
The command line hint handler. It gets called on every key insert to
|
The command line hint handler. It gets called on every key insert to
|
||||||
determine what text to use as an inline hint. It is passed the current
|
determine what text to use as an inline hint. It is passed the current
|
||||||
line and cursor position. It is expected to return a string which is used
|
line and cursor position. It is expected to return a string which is used
|
||||||
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.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -177,7 +177,7 @@ hilbish.inputMode(mode)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
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
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -190,8 +190,8 @@ hilbish.interval(cb, time) -> <a href="/Hilbish/docs/api/hilbish/hilbish.timers/
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Runs the `cb` function every `time` milliseconds.
|
Runs the `cb` function every `time` milliseconds.
|
||||||
This creates a timer that starts immediately.
|
This creates a timer that starts immediately.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -204,7 +204,7 @@ hilbish.multiprompt(str)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Changes the continued line prompt to `str`
|
Changes the continued line prompt to `str`
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -217,7 +217,7 @@ hilbish.prependPath(dir)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Prepends `dir` to $PATH
|
Prepends `dir` to $PATH
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -230,12 +230,12 @@ hilbish.prompt(str, typ)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Changes the shell prompt to `str`
|
Changes the shell prompt to `str`
|
||||||
There are a few verbs that can be used in the prompt text.
|
There are a few verbs that can be used in the prompt text.
|
||||||
These will be formatted and replaced with the appropriate values.
|
These will be formatted and replaced with the appropriate values.
|
||||||
`%d` - Current working directory
|
`%d` - Current working directory
|
||||||
`%u` - Name of current user
|
`%u` - Name of current user
|
||||||
`%h` - Hostname of device
|
`%h` - Hostname of device
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -248,9 +248,9 @@ hilbish.read(prompt) -> input (string)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
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)
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -263,9 +263,9 @@ hilbish.run(cmd, returnOut) -> exitCode (number), stdout (string), stderr (strin
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
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.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -278,11 +278,11 @@ hilbish.runnerMode(mode)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Sets the execution/runner mode for interactive Hilbish. This determines whether
|
Sets the execution/runner mode for interactive Hilbish. This determines whether
|
||||||
Hilbish wll try to run input as Lua and/or sh or only do one of either.
|
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),
|
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
|
sh, and lua. It also accepts a function, to which if it is passed one
|
||||||
will call it to execute user input instead.
|
will call it to execute user input instead.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -295,8 +295,8 @@ hilbish.timeout(cb, time) -> <a href="/Hilbish/docs/api/hilbish/hilbish.timers/#
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Runs the `cb` function after `time` in milliseconds.
|
Runs the `cb` function after `time` in milliseconds.
|
||||||
This creates a timer that starts immediately.
|
This creates a timer that starts immediately.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -309,8 +309,8 @@ hilbish.which(name) -> string
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Checks if `name` is a valid command.
|
Checks if `name` is a valid command.
|
||||||
Will return the path of the binary, or a basename if it's a commander.
|
Will return the path of the binary, or a basename if it's a commander.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -26,7 +26,7 @@ hilbish.aliases.add(alias, cmd)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
This is an alias (ha) for the `hilbish.alias` function.
|
This is an alias (ha) for the `hilbish.alias` function.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -39,7 +39,7 @@ hilbish.aliases.delete(name)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Removes an alias.
|
Removes an alias.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -52,7 +52,7 @@ hilbish.aliases.list() -> table\<string, string>
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Get a table of all aliases, with string keys as the alias and the value as the command.
|
Get a table of all aliases, with string keys as the alias and the value as the command.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -65,7 +65,7 @@ hilbish.aliases.resolve(alias) -> command (string)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Tries to resolve an alias to its command.
|
Tries to resolve an alias to its command.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -26,10 +26,10 @@ hilbish.completions.call(name, query, ctx, fields) -> completionGroups (table),
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
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`.
|
||||||
You can check `doc completions` for info on the `completionGroups` return value.
|
You can check `doc completions` for info on the `completionGroups` return value.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -42,8 +42,8 @@ hilbish.completions.handler(line, pos)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
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.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -56,7 +56,7 @@ hilbish.completions.bins(query, ctx, fields) -> entries (table), prefix (string)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Returns binary/executale completion candidates based on the provided query.
|
Returns binary/executale completion candidates based on the provided query.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -69,7 +69,7 @@ hilbish.completions.files(query, ctx, fields) -> entries (table), prefix (string
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Returns file completion candidates based on the provided query.
|
Returns file completion candidates based on the provided query.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -28,7 +28,7 @@ hilbish.editor.getLine() -> string
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Returns the current input line.
|
Returns the current input line.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -41,7 +41,7 @@ hilbish.editor.getVimRegister(register) -> string
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Returns the text that is at the register.
|
Returns the text that is at the register.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -54,7 +54,7 @@ hilbish.editor.insert(text)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Inserts text into the line.
|
Inserts text into the line.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -67,8 +67,8 @@ hilbish.editor.getChar() -> string
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Reads a keystroke from the user. This is in a format
|
Reads a keystroke from the user. This is in a format
|
||||||
of something like Ctrl-L..
|
of something like Ctrl-L..
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -81,7 +81,7 @@ hilbish.editor.setVimRegister(register, text)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Sets the vim register at `register` to hold the passed text.
|
Sets the vim register at `register` to hold the passed text.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -29,7 +29,7 @@ hilbish.history.add(cmd)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Adds a command to the history.
|
Adds a command to the history.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -42,7 +42,7 @@ hilbish.history.all() -> table
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Retrieves all history.
|
Retrieves all history.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -55,7 +55,7 @@ hilbish.history.clear()
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Deletes all commands from the history.
|
Deletes all commands from the history.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -68,7 +68,7 @@ hilbish.history.get(idx)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Retrieves a command from the history based on the `idx`.
|
Retrieves a command from the history based on the `idx`.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -81,7 +81,7 @@ hilbish.history.size() -> number
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Returns the amount of commands in the history.
|
Returns the amount of commands in the history.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -31,7 +31,7 @@ hilbish.jobs.add(cmdstr, args, execPath)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
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.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -44,7 +44,7 @@ hilbish.jobs.all() -> table\<<a href="/Hilbish/docs/api/hilbish/hilbish.jobs/#jo
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Returns a table of all job objects.
|
Returns a table of all job objects.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -57,7 +57,7 @@ hilbish.jobs.disown(id)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Disowns a job. This deletes it from the job table.
|
Disowns a job. This deletes it from the job table.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -70,7 +70,7 @@ hilbish.jobs.get(id) -> <a href="/Hilbish/docs/api/hilbish/hilbish.jobs/#job" st
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Get a job object via its ID.
|
Get a job object via its ID.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -83,7 +83,7 @@ hilbish.jobs.last() -> <a href="/Hilbish/docs/api/hilbish/hilbish.jobs/#job" sty
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Returns the last added job from the table.
|
Returns the last added job from the table.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -61,8 +61,8 @@ hilbish.module.load(path)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Loads a module at the designated `path`.
|
Loads a module at the designated `path`.
|
||||||
It will throw if any error occurs.
|
It will throw if any error occurs.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -29,10 +29,10 @@ hilbish.runner.setMode(cb)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
This is the same as the `hilbish.runnerMode` function. It takes a callback,
|
This is the same as the `hilbish.runnerMode` function. It takes a callback,
|
||||||
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.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -45,8 +45,8 @@ hilbish.runner.lua(cmd)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
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.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -59,8 +59,8 @@ hilbish.runner.sh(cmd)
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
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`.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -50,8 +50,8 @@ hilbish.timers.create(type, time, callback) -> <a href="/Hilbish/docs/api/hilbis
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
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 `hilbish.timers.INTERVAL` or `hilbish.timers.TIMEOUT`
|
The `type` can either be `hilbish.timers.INTERVAL` or `hilbish.timers.TIMEOUT`
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -64,7 +64,7 @@ hilbish.timers.get(id) -> <a href="/Hilbish/docs/api/hilbish/hilbish.timers/#tim
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Retrieves a timer via its ID.
|
Retrieves a timer via its ID.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -26,7 +26,7 @@ terminal.restoreState()
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Restores the last saved state of the terminal
|
Restores the last saved state of the terminal
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -39,7 +39,7 @@ terminal.saveState()
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Saves the current state of the terminal
|
Saves the current state of the terminal
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -52,7 +52,7 @@ terminal.setRaw()
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Puts the terminal in raw mode
|
Puts the terminal in raw mode
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
@ -65,8 +65,8 @@ terminal.size()
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
Gets the dimensions of the terminal. Returns a table with `width` and `height`
|
Gets the dimensions of the terminal. Returns a table with `width` and `height`
|
||||||
Note: this is not the size in relation to the dimensions of the display
|
Note: this is not the size in relation to the dimensions of the display
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
This function has no parameters.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,56 +2,51 @@
|
||||||
|
|
||||||
local fs = {}
|
local fs = {}
|
||||||
|
|
||||||
--- Gives an absolute version of `path`.
|
--- Returns an absolute version of the `path`.
|
||||||
--- @param path string
|
--- This can be used to resolve short paths like `..` to `/home/user`.
|
||||||
--- @returns string
|
|
||||||
function fs.abs(path) end
|
function fs.abs(path) end
|
||||||
|
|
||||||
--- Gives the basename of `path`. For the rules,
|
--- Returns the "basename," or the last part of the provided `path`. If path is empty,
|
||||||
--- see Go's filepath.Base
|
--- `.` will be returned.
|
||||||
--- @returns string
|
|
||||||
function fs.basename(path) end
|
function fs.basename(path) end
|
||||||
|
|
||||||
--- Changes directory to `dir`
|
--- Changes Hilbish's directory to `dir`.
|
||||||
--- @param dir string
|
|
||||||
function fs.cd(dir) end
|
function fs.cd(dir) end
|
||||||
|
|
||||||
--- Returns the directory part of `path`. For the rules, see Go's
|
--- Returns the directory part of `path`. If a file path like
|
||||||
--- filepath.Dir
|
--- `~/Documents/doc.txt` then this function will return `~/Documents`.
|
||||||
--- @param path string
|
|
||||||
--- @returns string
|
|
||||||
function fs.dir(path) end
|
function fs.dir(path) end
|
||||||
|
|
||||||
--- Glob all files and directories that match the pattern.
|
--- Match all files based on the provided `pattern`.
|
||||||
--- For the rules, see Go's filepath.Glob
|
--- For the syntax' refer to Go's filepath.Match function: https://pkg.go.dev/path/filepath#Match
|
||||||
--- @param pattern string
|
---
|
||||||
--- @returns table
|
---
|
||||||
function fs.glob(pattern) end
|
function fs.glob(pattern) end
|
||||||
|
|
||||||
--- Takes paths and joins them together with the OS's
|
--- Takes any list of paths and joins them based on the operating system's path separator.
|
||||||
--- directory separator (forward or backward slash).
|
---
|
||||||
--- @vararg string
|
---
|
||||||
--- @returns string
|
function fs.join(...path) end
|
||||||
function fs.join(...) end
|
|
||||||
|
|
||||||
--- Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
|
--- Creates a new directory with the provided `name`.
|
||||||
--- @param name string
|
--- With `recursive`, mkdir will create parent directories.
|
||||||
--- @param recursive boolean
|
---
|
||||||
|
--- -- This will create the directory foo, then create the directory bar in the
|
||||||
|
--- -- foo directory. If recursive is false in this case, it will fail.
|
||||||
|
--- fs.mkdir('./foo/bar', true)
|
||||||
function fs.mkdir(name, recursive) end
|
function fs.mkdir(name, recursive) end
|
||||||
|
|
||||||
--- Returns a table of files in `dir`.
|
--- Returns a list of all files and directories in the provided path.
|
||||||
--- @param dir string
|
function fs.readdir(path) end
|
||||||
--- @return table
|
|
||||||
function fs.readdir(dir) end
|
|
||||||
|
|
||||||
--- Returns a table of info about the `path`.
|
--- Returns the information about a given `path`.
|
||||||
--- It contains the following keys:
|
--- The returned table contains the following values:
|
||||||
--- name (string) - Name of the path
|
--- name (string) - Name of the path
|
||||||
--- size (number) - Size of the path
|
--- size (number) - Size of the path in bytes
|
||||||
--- mode (string) - Permission mode in an octal format string (with leading 0)
|
--- mode (string) - Unix permission mode in an octal format string (with leading 0)
|
||||||
--- isDir (boolean) - If the path is a directory
|
--- isDir (boolean) - If the path is a directory
|
||||||
--- @param path string
|
---
|
||||||
--- @returns table
|
---
|
||||||
function fs.stat(path) end
|
function fs.stat(path) end
|
||||||
|
|
||||||
return fs
|
return fs
|
||||||
|
|
328
golibs/fs/fs.go
328
golibs/fs/fs.go
|
@ -1,7 +1,10 @@
|
||||||
// filesystem interaction and functionality library
|
// filesystem interaction and functionality library
|
||||||
// The fs module provides easy and simple access to filesystem functions
|
/*
|
||||||
// and other things, and acts an addition to the Lua standard library's
|
The fs module provides filesystem functions to Hilbish. While Lua's standard
|
||||||
// I/O and filesystem functions.
|
library has some I/O functions, they're missing a lot of the basics. The `fs`
|
||||||
|
library offers more functions and will work on any operating system Hilbish does.
|
||||||
|
#field pathSep The operating system's path separator.
|
||||||
|
*/
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -42,9 +45,46 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
|
||||||
return rt.TableValue(mod), nil
|
return rt.TableValue(mod), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// abs(path) -> string
|
||||||
|
// Returns an absolute version of the `path`.
|
||||||
|
// 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) {
|
||||||
|
path, err := c.StringArg(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
path = util.ExpandHome(path)
|
||||||
|
|
||||||
|
abspath, err := filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.PushingNext1(t.Runtime, rt.StringValue(abspath)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// basename(path) -> string
|
||||||
|
// Returns the "basename," or the last part of the provided `path`. If path is empty,
|
||||||
|
// `.` 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) {
|
||||||
|
if err := c.Check1Arg(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
path, err := c.StringArg(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.PushingNext(t.Runtime, rt.StringValue(filepath.Base(path))), nil
|
||||||
|
}
|
||||||
|
|
||||||
// cd(dir)
|
// cd(dir)
|
||||||
// Changes directory to `dir`
|
// Changes Hilbish's directory to `dir`.
|
||||||
// --- @param dir string
|
// #param dir string Path to change directory to.
|
||||||
func fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func fcd(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
|
||||||
|
@ -63,10 +103,102 @@ func fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
return c.Next(), err
|
return c.Next(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dir(path) -> string
|
||||||
|
// Returns the directory part of `path`. If a file path like
|
||||||
|
// `~/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) {
|
||||||
|
if err := c.Check1Arg(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
path, err := c.StringArg(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.PushingNext(t.Runtime, rt.StringValue(filepath.Dir(path))), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// glob(pattern) -> matches (table)
|
||||||
|
// Match all files based on the provided `pattern`.
|
||||||
|
// For the syntax' refer to Go's filepath.Match function: https://pkg.go.dev/path/filepath#Match
|
||||||
|
// #param pattern string Pattern to compare files with.
|
||||||
|
// #returns table A list of file names/paths that match.
|
||||||
|
/*
|
||||||
|
#example
|
||||||
|
--[[
|
||||||
|
Within a folder that contains the following files:
|
||||||
|
a.txt
|
||||||
|
init.lua
|
||||||
|
code.lua
|
||||||
|
doc.pdf
|
||||||
|
]]--
|
||||||
|
local matches = fs.glob './*.lua'
|
||||||
|
print(matches)
|
||||||
|
-- -> {'init.lua', 'code.lua'}
|
||||||
|
#example
|
||||||
|
*/
|
||||||
|
func fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
|
if err := c.Check1Arg(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pattern, err := c.StringArg(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
matches, err := filepath.Glob(pattern)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
luaMatches := rt.NewTable()
|
||||||
|
|
||||||
|
for i, match := range matches {
|
||||||
|
luaMatches.Set(rt.IntValue(int64(i + 1)), rt.StringValue(match))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.PushingNext(t.Runtime, rt.TableValue(luaMatches)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// join(...path) -> string
|
||||||
|
// Takes any list of paths and joins them based on the operating system's path separator.
|
||||||
|
// #param path ...string Paths to join together
|
||||||
|
// #returns string The joined path.
|
||||||
|
/*
|
||||||
|
#example
|
||||||
|
-- This prints the directory for Hilbish's config!
|
||||||
|
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) {
|
||||||
|
strs := make([]string, len(c.Etc()))
|
||||||
|
for i, v := range c.Etc() {
|
||||||
|
if v.Type() != rt.StringType {
|
||||||
|
// +2; go indexes of 0 and first arg from above
|
||||||
|
return nil, fmt.Errorf("bad argument #%d to run (expected string, got %s)", i + 1, v.TypeName())
|
||||||
|
}
|
||||||
|
strs[i] = v.AsString()
|
||||||
|
}
|
||||||
|
|
||||||
|
res := filepath.Join(strs...)
|
||||||
|
|
||||||
|
return c.PushingNext(t.Runtime, rt.StringValue(res)), nil
|
||||||
|
}
|
||||||
|
|
||||||
// mkdir(name, recursive)
|
// mkdir(name, recursive)
|
||||||
// Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
|
// Creates a new directory with the provided `name`.
|
||||||
// --- @param name string
|
// With `recursive`, mkdir will create parent directories.
|
||||||
// --- @param recursive boolean
|
// #param name string Name of the directory
|
||||||
|
// #param recursive boolean Whether to create parent directories for the provided name
|
||||||
|
/*
|
||||||
|
#example
|
||||||
|
-- This will create the directory foo, then create the directory bar in the
|
||||||
|
-- foo directory. If recursive is false in this case, it will fail.
|
||||||
|
fs.mkdir('./foo/bar', true)
|
||||||
|
*/
|
||||||
func fmkdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func fmkdir(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
|
||||||
|
@ -93,15 +225,58 @@ func fmkdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
return c.Next(), err
|
return c.Next(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// readdir(path) -> table[string]
|
||||||
|
// 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) {
|
||||||
|
if err := c.Check1Arg(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dir, err := c.StringArg(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dir = util.ExpandHome(dir)
|
||||||
|
names := rt.NewTable()
|
||||||
|
|
||||||
|
dirEntries, err := os.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for i, entry := range dirEntries {
|
||||||
|
names.Set(rt.IntValue(int64(i + 1)), rt.StringValue(entry.Name()))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.PushingNext1(t.Runtime, rt.TableValue(names)), nil
|
||||||
|
}
|
||||||
|
|
||||||
// stat(path) -> {}
|
// stat(path) -> {}
|
||||||
// Returns a table of info about the `path`.
|
// Returns the information about a given `path`.
|
||||||
// It contains the following keys:
|
// The returned table contains the following values:
|
||||||
// name (string) - Name of the path
|
// name (string) - Name of the path
|
||||||
// size (number) - Size of the path
|
// size (number) - Size of the path in bytes
|
||||||
// mode (string) - Permission mode in an octal format string (with leading 0)
|
// mode (string) - Unix permission mode in an octal format string (with leading 0)
|
||||||
// isDir (boolean) - If the path is a directory
|
// isDir (boolean) - If the path is a directory
|
||||||
// --- @param path string
|
// #param path string
|
||||||
// --- @returns table
|
// #returns table
|
||||||
|
/*
|
||||||
|
#example
|
||||||
|
local inspect = require 'inspect'
|
||||||
|
|
||||||
|
local stat = fs.stat '~'
|
||||||
|
print(inspect(stat))
|
||||||
|
--[[
|
||||||
|
Would print the following:
|
||||||
|
{
|
||||||
|
isDir = true,
|
||||||
|
mode = "0755",
|
||||||
|
name = "username",
|
||||||
|
size = 12288
|
||||||
|
}
|
||||||
|
]]--
|
||||||
|
#example
|
||||||
|
*/
|
||||||
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
|
||||||
|
@ -125,128 +300,3 @@ 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) -> {}
|
|
||||||
// Returns a table of files in `dir`.
|
|
||||||
// --- @param dir string
|
|
||||||
// --- @return table
|
|
||||||
func freaddir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|
||||||
if err := c.Check1Arg(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
dir, err := c.StringArg(0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
dir = util.ExpandHome(dir)
|
|
||||||
names := rt.NewTable()
|
|
||||||
|
|
||||||
dirEntries, err := os.ReadDir(dir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for i, entry := range dirEntries {
|
|
||||||
names.Set(rt.IntValue(int64(i + 1)), rt.StringValue(entry.Name()))
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.PushingNext1(t.Runtime, rt.TableValue(names)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// abs(path) -> string
|
|
||||||
// Gives an absolute version of `path`.
|
|
||||||
// --- @param path string
|
|
||||||
// --- @returns string
|
|
||||||
func fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|
||||||
path, err := c.StringArg(0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
path = util.ExpandHome(path)
|
|
||||||
|
|
||||||
abspath, err := filepath.Abs(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.PushingNext1(t.Runtime, rt.StringValue(abspath)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// basename(path) -> string
|
|
||||||
// Gives the basename of `path`. For the rules,
|
|
||||||
// see Go's filepath.Base
|
|
||||||
// --- @returns string
|
|
||||||
func fbasename(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|
||||||
if err := c.Check1Arg(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
path, err := c.StringArg(0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.PushingNext(t.Runtime, rt.StringValue(filepath.Base(path))), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// dir(path) -> string
|
|
||||||
// Returns the directory part of `path`. For the rules, see Go's
|
|
||||||
// filepath.Dir
|
|
||||||
// --- @param path string
|
|
||||||
// --- @returns string
|
|
||||||
func fdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|
||||||
if err := c.Check1Arg(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
path, err := c.StringArg(0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.PushingNext(t.Runtime, rt.StringValue(filepath.Dir(path))), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// glob(pattern) -> matches (table)
|
|
||||||
// Glob all files and directories that match the pattern.
|
|
||||||
// For the rules, see Go's filepath.Glob
|
|
||||||
// --- @param pattern string
|
|
||||||
// --- @returns table
|
|
||||||
func fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|
||||||
if err := c.Check1Arg(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
pattern, err := c.StringArg(0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
matches, err := filepath.Glob(pattern)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
luaMatches := rt.NewTable()
|
|
||||||
|
|
||||||
for i, match := range matches {
|
|
||||||
luaMatches.Set(rt.IntValue(int64(i + 1)), rt.StringValue(match))
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.PushingNext(t.Runtime, rt.TableValue(luaMatches)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// join(...) -> string
|
|
||||||
// Takes paths and joins them together with the OS's
|
|
||||||
// directory separator (forward or backward slash).
|
|
||||||
// --- @vararg string
|
|
||||||
// --- @returns string
|
|
||||||
func 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 {
|
|
||||||
// +2; go indexes of 0 and first arg from above
|
|
||||||
return nil, fmt.Errorf("bad argument #%d to run (expected string, got %s)", i + 1, v.TypeName())
|
|
||||||
}
|
|
||||||
strs[i] = v.AsString()
|
|
||||||
}
|
|
||||||
|
|
||||||
res := filepath.Join(strs...)
|
|
||||||
|
|
||||||
return c.PushingNext(t.Runtime, rt.StringValue(res)), nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
baseURL = 'https://rosettea.github.io/Hilbish/'
|
|
||||||
languageCode = 'en-us'
|
languageCode = 'en-us'
|
||||||
|
baseURL = 'https://rosettea.github.io/Hilbish/'
|
||||||
title = 'Hilbish'
|
title = 'Hilbish'
|
||||||
theme = 'hsh'
|
theme = 'hsh'
|
||||||
enableGitInfo = true
|
enableGitInfo = true
|
||||||
|
@ -34,6 +34,7 @@ lineNos = true
|
||||||
lineNumbersInTable = false
|
lineNumbersInTable = false
|
||||||
noClasses = false
|
noClasses = false
|
||||||
codeFences = true
|
codeFences = true
|
||||||
|
guessSyntax = true
|
||||||
|
|
||||||
[author]
|
[author]
|
||||||
[author.sammyette]
|
[author.sammyette]
|
||||||
|
|
Loading…
Reference in New Issue