2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-06-06 12:32:03 +00:00

157 lines
15 KiB
HTML

<!doctype html>
<html class="bg-stone-50 dark:bg-neutral-900 text-black dark:text-white"><head><meta content="width=device-width, initial-scale=1.0" name="viewport"><link href="/tailwind.css" rel="stylesheet"><title>Hilbish</title><meta content="#ff89dd" name="theme-color"><meta content="/hilbish-flower.png" property="og:image"><meta content="Hilbish" property="og:title"><meta content="Hilbish" property="og:site_name"><meta content="website" property="og:type"><meta content="Something Unique. Hilbish is the new interactive shell for Lua fans. Extensible, scriptable, configurable: All in Lua." property="og:description"><meta content="Something Unique. Hilbish is the new interactive shell for Lua fans. Extensible, scriptable, configurable: All in Lua." name="description"><meta content="Lua,Shell,Hilbish,Linux,zsh,bash" name="keywords"><meta content property="og:url"></head><body class="min-h-screen flex flex-col"><nav class="flex sticky top-0 w-full z-50 border-b border-b-zinc-300 backdrop-blur-md h-12"><div class="flex my-auto px-2"><div><a class="flex items-center gap-1" href="/"><img class="h-6" src="/hilbish-flower.png"><span class="self-center text-2xl">Hilbish</span></a></div></div></nav><div class="flex flex-col"><div class="h-10 flex py-2 px-4 border-b border-b-zinc-300 w-full gap-2 backdrop-blur-sm bg-zinc-300/50 dark:bg-zinc-800/50 z-50"><label class="cursor-pointer" for="sidebar-toggle"><tag><svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" class="fill-black"><path d="M120-240v-80h240v80H120Zm0-200v-80h480v80H120Zm0-200v-80h720v80H120Z"/></svg></tag></label><span>Module fs</span></div><div class="grid"><input class="peer hidden" id="sidebar-toggle" type="checkbox"><div class="border-r border-r-zinc-300 col-start-1 row-start-1 sticky top-22 sm:top-12 h-full sm:h-svh bg-neutral-200 dark:bg-neutral-900 basis-3/5 transition-transform duration-300 -translate-x-full peer-checked:translate-x-0 z-30"><div class="p-4 -mb-4 overflow-y-auto h-full"><h2 class="text-xl font-semibold mb-4">Sidebar</h2><ul><li class="mb-2">Vim Mode</li><li class="mb-2">Completions</li><li class="mb-2">Lunacolors</li><li class="mb-2">Frequently Asked Questions</li><li class="mb-2">Getting Started</li><li class="mb-2">Introduction</li><li class="mb-2">Module hilbish</li><li class="mb-2">Module fs</li><li class="mb-2">Module snail</li><li class="mb-2">Module terminal</li><li class="mb-2">Module commander</li><li class="mb-2">API</li><li class="mb-2">Module bait</li><li class="mb-2">Module hilbish.module</li><li class="mb-2">Module hilbish.abbr</li><li class="mb-2">Module hilbish.userDir</li><li class="mb-2">Module hilbish.os</li><li class="mb-2">Module hilbish.history</li><li class="mb-2">Module hilbish.completion</li><li class="mb-2">Module hilbish.messages</li><li class="mb-2">Module hilbish.aliases</li><li class="mb-2">Module hilbish.runner</li><li class="mb-2">Module hilbish.timers</li><li class="mb-2">Module hilbish</li><li class="mb-2">Module hilbish.jobs</li><li class="mb-2">Module hilbish.editor</li><li class="mb-2">Actions</li><li class="mb-2">Module doc</li><li class="mb-2">Nature</li><li class="mb-2">Module dirs</li><li class="mb-2">Hilbish</li><li class="mb-2">Command</li><li class="mb-2">Signals</li><li class="mb-2">Signal</li><li class="mb-2">Notification</li><li class="mb-2">Runner Mode</li><li class="mb-2">Options</li><li class="mb-2">Features</li></ul></div></div><main class="col-start-1 row-start-1 transition-all duration-300 peer-checked:filter peer-checked:blur-sm peer-checked:bg-black/30 px-4 pt-2"><h1 class="font-bold text-4xl">Module fs</h1><h2 class="font-bold text-3xl" id="Introduction">Introduction</h2><p>The fs module provides filesystem functions to Hilbish. While Lua&#39;s standard
library has some I/O functions, they&#39;re missing a lot of the basics. The <code>fs</code>
library offers more functions and will work on any operating system Hilbish does.</p><h2 class="font-bold text-3xl" id="Functions-|||-|----|----|-|&lt;a-href=&quot;abs&quot;&gt;abs(path)--&gt;-string&lt;/a&gt;|Returns-an-absolute-version-of-the-path.|-|&lt;a-href=&quot;basename&quot;&gt;basename(path)--&gt;-string&lt;/a&gt;|Returns-the-&quot;basename&quot;-or-the-last-part-of-the-provided-path.-If-path-is-empty|-|&lt;a-href=&quot;cd&quot;&gt;cd(dir)&lt;/a&gt;|Changes-Hilbish&#39;s-directory-to-dir.|-|&lt;a-href=&quot;dir&quot;&gt;dir(path)--&gt;-string&lt;/a&gt;|Returns-the-directory-part-of-path.-If-a-file-path-like|-|&lt;a-href=&quot;glob&quot;&gt;glob(pattern)--&gt;-matches-(table)&lt;/a&gt;|Match-all-files-based-on-the-provided-pattern.|-|&lt;a-href=&quot;join&quot;&gt;join(...path)--&gt;-string&lt;/a&gt;|Takes-any-list-of-paths-and-joins-them-based-on-the-operating-system&#39;s-path-separator.|-|&lt;a-href=&quot;mkdir&quot;&gt;mkdir(name-recursive)&lt;/a&gt;|Creates-a-new-directory-with-the-provided-name.|-|&lt;a-href=&quot;pipe&quot;&gt;fpipe()--&gt;-File-File&lt;/a&gt;|Returns-a-pair-of-connected-files-also-known-as-a-pipe.|-|&lt;a-href=&quot;readdir&quot;&gt;readdir(path)--&gt;-table[string]&lt;/a&gt;|Returns-a-list-of-all-files-and-directories-in-the-provided-path.|-|&lt;a-href=&quot;stat&quot;&gt;stat(path)--&gt;-{}&lt;/a&gt;|Returns-the-information-about-a-given-path.|">Functions
|||
|----|----|
|&lt;a href=&quot;#abs&quot;&gt;abs(path) -&gt; string&lt;/a&gt;|Returns an absolute version of the <code>path</code>.|
|&lt;a href=&quot;#basename&quot;&gt;basename(path) -&gt; string&lt;/a&gt;|Returns the &quot;basename,&quot; or the last part of the provided <code>path</code>. If path is empty,|
|&lt;a href=&quot;#cd&quot;&gt;cd(dir)&lt;/a&gt;|Changes Hilbish&#39;s directory to <code>dir</code>.|
|&lt;a href=&quot;#dir&quot;&gt;dir(path) -&gt; string&lt;/a&gt;|Returns the directory part of <code>path</code>. If a file path like|
|&lt;a href=&quot;#glob&quot;&gt;glob(pattern) -&gt; matches (table)&lt;/a&gt;|Match all files based on the provided <code>pattern</code>.|
|&lt;a href=&quot;#join&quot;&gt;join(...path) -&gt; string&lt;/a&gt;|Takes any list of paths and joins them based on the operating system&#39;s path separator.|
|&lt;a href=&quot;#mkdir&quot;&gt;mkdir(name, recursive)&lt;/a&gt;|Creates a new directory with the provided <code>name</code>.|
|&lt;a href=&quot;#pipe&quot;&gt;fpipe() -&gt; File, File&lt;/a&gt;|Returns a pair of connected files, also known as a pipe.|
|&lt;a href=&quot;#readdir&quot;&gt;readdir(path) -&gt; table[string]&lt;/a&gt;|Returns a list of all files and directories in the provided path.|
|&lt;a href=&quot;#stat&quot;&gt;stat(path) -&gt; {}&lt;/a&gt;|Returns the information about a given <code>path</code>.|</h2><h2 class="font-bold text-3xl" id="Static-module-fields-|||-|----|----|-|pathSep|The-operating-system&#39;s-path-separator.|">Static module fields
|||
|----|----|
|pathSep|The operating system&#39;s path separator.|</h2><p>&lt;hr&gt;
&lt;div id=&#39;abs&#39;&gt;
&lt;h4 class=&#39;heading&#39;&gt;
fs.abs(path) -&gt; string
&lt;a href=&quot;#abs&quot; class=&#39;heading-link&#39;&gt;
&lt;i class=&quot;fas fa-paperclip&quot;&gt;&lt;/i&gt;
&lt;/a&gt;
&lt;/h4&gt;</p><p>Returns an absolute version of the <code>path</code>.
This can be used to resolve short paths like <code>..</code> to <code>/home/user</code>. </p><p class="font-bold text-xl" id="Parameters-string-**path**">Parameters
<code>string</code> **<code>path</code>** </p><p>&lt;/div&gt;</p><p>&lt;hr&gt;
&lt;div id=&#39;basename&#39;&gt;
&lt;h4 class=&#39;heading&#39;&gt;
fs.basename(path) -&gt; string
&lt;a href=&quot;#basename&quot; class=&#39;heading-link&#39;&gt;
&lt;i class=&quot;fas fa-paperclip&quot;&gt;&lt;/i&gt;
&lt;/a&gt;
&lt;/h4&gt;</p><p>Returns the &quot;basename,&quot; or the last part of the provided <code>path</code>. If path is empty,
<code>.</code> will be returned. </p><p class="font-bold text-xl" id="Parameters-string-**path**---Path-to-get-the-base-name-of.">Parameters
<code>string</code> **<code>path</code>**
Path to get the base name of.</p><p>&lt;/div&gt;</p><p>&lt;hr&gt;
&lt;div id=&#39;cd&#39;&gt;
&lt;h4 class=&#39;heading&#39;&gt;
fs.cd(dir)
&lt;a href=&quot;#cd&quot; class=&#39;heading-link&#39;&gt;
&lt;i class=&quot;fas fa-paperclip&quot;&gt;&lt;/i&gt;
&lt;/a&gt;
&lt;/h4&gt;</p><p>Changes Hilbish&#39;s directory to <code>dir</code>. </p><p class="font-bold text-xl" id="Parameters-string-**dir**---Path-to-change-directory-to.">Parameters
<code>string</code> **<code>dir</code>**
Path to change directory to.</p><p>&lt;/div&gt;</p><p>&lt;hr&gt;
&lt;div id=&#39;dir&#39;&gt;
&lt;h4 class=&#39;heading&#39;&gt;
fs.dir(path) -&gt; string
&lt;a href=&quot;#dir&quot; class=&#39;heading-link&#39;&gt;
&lt;i class=&quot;fas fa-paperclip&quot;&gt;&lt;/i&gt;
&lt;/a&gt;
&lt;/h4&gt;</p><p>Returns the directory part of <code>path</code>. If a file path like
<code>~/Documents/doc.txt</code> then this function will return <code>~/Documents</code>. </p><p class="font-bold text-xl" id="Parameters-string-**path**---Path-to-get-the-directory-for.">Parameters
<code>string</code> **<code>path</code>**
Path to get the directory for.</p><p>&lt;/div&gt;</p><p>&lt;hr&gt;
&lt;div id=&#39;glob&#39;&gt;
&lt;h4 class=&#39;heading&#39;&gt;
fs.glob(pattern) -&gt; matches (table)
&lt;a href=&quot;#glob&quot; class=&#39;heading-link&#39;&gt;
&lt;i class=&quot;fas fa-paperclip&quot;&gt;&lt;/i&gt;
&lt;/a&gt;
&lt;/h4&gt;</p><p>Match all files based on the provided <code>pattern</code>.
For the syntax&#39; refer to Go&#39;s filepath.Match function: https://pkg.go.dev/path/filepath#Match </p><p class="font-bold text-xl" id="Parameters-string-**pattern**---Pattern-to-compare-files-with.">Parameters
<code>string</code> **<code>pattern</code>**
Pattern to compare files with.</p><p class="font-bold text-xl" id="Example-lua---[[- Within-a-folder-that-contains-the-following-files:- a.txt- init.lua- code.lua- doc.pdf-]]---local-matches-=-fs.glob-&#39;./*.lua&#39;-print(matches)-----&gt;-{&#39;init.lua&#39;-&#39;code.lua&#39;}--&lt;/div&gt;">Example
<code>lua
--[[
Within a folder that contains the following files:
a.txt
init.lua
code.lua
doc.pdf
]]--
local matches = fs.glob &#39;./*.lua&#39;
print(matches)
-- -&gt; {&#39;init.lua&#39;, &#39;code.lua&#39;}
</code>
&lt;/div&gt;</p><p>&lt;hr&gt;
&lt;div id=&#39;join&#39;&gt;
&lt;h4 class=&#39;heading&#39;&gt;
fs.join(...path) -&gt; string
&lt;a href=&quot;#join&quot; class=&#39;heading-link&#39;&gt;
&lt;i class=&quot;fas fa-paperclip&quot;&gt;&lt;/i&gt;
&lt;/a&gt;
&lt;/h4&gt;</p><p>Takes any list of paths and joins them based on the operating system&#39;s path separator. </p><p class="font-bold text-xl" id="Parameters-string-**path**-(This-type-is-variadic.-You-can-pass-an-infinite-amount-of-parameters-with-this-type.)---Paths-to-join-together">Parameters
<code>string</code> **<code>path</code>** (This type is variadic. You can pass an infinite amount of parameters with this type.)
Paths to join together</p><p class="font-bold text-xl" id="Example-lua----This-prints-the-directory-for-Hilbish&#39;s-config-print(fs.join(hilbish.userDir.config-&#39;hilbish&#39;))-----&gt;-&#39;/home/user/.config/hilbish&#39;-on-Linux--&lt;/div&gt;">Example
<code>lua
-- This prints the directory for Hilbish&#39;s config!
print(fs.join(hilbish.userDir.config, &#39;hilbish&#39;))
-- -&gt; &#39;/home/user/.config/hilbish&#39; on Linux
</code>
&lt;/div&gt;</p><p>&lt;hr&gt;
&lt;div id=&#39;mkdir&#39;&gt;
&lt;h4 class=&#39;heading&#39;&gt;
fs.mkdir(name, recursive)
&lt;a href=&quot;#mkdir&quot; class=&#39;heading-link&#39;&gt;
&lt;i class=&quot;fas fa-paperclip&quot;&gt;&lt;/i&gt;
&lt;/a&gt;
&lt;/h4&gt;</p><p>Creates a new directory with the provided <code>name</code>.
With <code>recursive</code>, mkdir will create parent directories. </p><p class="font-bold text-xl" id="Parameters-string-**name**---Name-of-the-directory">Parameters
<code>string</code> **<code>name</code>**
Name of the directory</p><p><code>boolean</code> **<code>recursive</code>**
Whether to create parent directories for the provided name</p><p class="font-bold text-xl" id="Example-lua----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(&#39;./foo/bar&#39;-true)--&lt;/div&gt;">Example
<code>lua
-- 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(&#39;./foo/bar&#39;, true)
</code>
&lt;/div&gt;</p><p>&lt;hr&gt;
&lt;div id=&#39;pipe&#39;&gt;
&lt;h4 class=&#39;heading&#39;&gt;
fs.fpipe() -&gt; File, File
&lt;a href=&quot;#pipe&quot; class=&#39;heading-link&#39;&gt;
&lt;i class=&quot;fas fa-paperclip&quot;&gt;&lt;/i&gt;
&lt;/a&gt;
&lt;/h4&gt;</p><p>Returns a pair of connected files, also known as a pipe.
The type returned is a Lua file, same as returned from <code>io</code> functions. </p><p class="font-bold text-xl" id="Parameters-This-function-has-no-parameters.---&lt;/div&gt;">Parameters
This function has no parameters.
&lt;/div&gt;</p><p>&lt;hr&gt;
&lt;div id=&#39;readdir&#39;&gt;
&lt;h4 class=&#39;heading&#39;&gt;
fs.readdir(path) -&gt; table[string]
&lt;a href=&quot;#readdir&quot; class=&#39;heading-link&#39;&gt;
&lt;i class=&quot;fas fa-paperclip&quot;&gt;&lt;/i&gt;
&lt;/a&gt;
&lt;/h4&gt;</p><p>Returns a list of all files and directories in the provided path. </p><p class="font-bold text-xl" id="Parameters-string-**dir**">Parameters
<code>string</code> **<code>dir</code>** </p><p>&lt;/div&gt;</p><p>&lt;hr&gt;
&lt;div id=&#39;stat&#39;&gt;
&lt;h4 class=&#39;heading&#39;&gt;
fs.stat(path) -&gt; {}
&lt;a href=&quot;#stat&quot; class=&#39;heading-link&#39;&gt;
&lt;i class=&quot;fas fa-paperclip&quot;&gt;&lt;/i&gt;
&lt;/a&gt;
&lt;/h4&gt;</p><p>Returns the information about a given <code>path</code>.
The returned table contains the following values:
name (string) - Name of the path
size (number) - Size of the path in bytes
mode (string) - Unix permission mode in an octal format string (with leading 0)
isDir (boolean) - If the path is a directory </p><p class="font-bold text-xl">Parameters
<code>string</code> **<code>path</code>** </p><p class="font-bold text-xl" id="Example-lua-local-inspect-=-require-&#39;inspect&#39;">Example
<code>lua
local inspect = require &#39;inspect&#39;</code></p><p>local stat = fs.stat &#39;~&#39;
print(inspect(stat))
--[[
Would print the following:
{
isDir = true,
mode = &quot;0755&quot;,
name = &quot;username&quot;,
size = 12288
}
]]--
<code>
&lt;/div&gt;</code></p></main></div></div><footer class="py-4 px-6 flex flex-row justify-around border-t border-t-zinc-300"><div class="flex flex-col"><a class="flex items-center gap-1" href><img class="h-24" src="/hilbish-flower.png"><span class="self-center text-6xl">Hilbish</span></a><span class="text-xl">The Moon-powered shell!</span><span class="text-light text-neutral-500">MIT License, copyright sammyette 2025</span></div><div class="flex flex-col"><a href="https://github.com/Rosettea/Hilbish"><span class="text-pink-300 text-light">GitHub</span></a></div></footer></body></html>