elvish-file(7)
π elvish-file β the file: module, but make it make sense π
elvish-file(7) Β· Miscellaneous Information Manual Β· bestie edition π
πΈ Introduction πΈ
Okay so the file: module? It's the whole toolbox for manipulating file objects. That's it, that's the vibe. π«Ά
And fr fr, function usages in here are written in the exact same format as the reference doc for the builtin module β so if you already know that format, you're already slaying. No cap. β¨
π₯ Functions π₯
β¨ file:close {#file:close} β¨
file:close $file
Closes a file that was opened with open. Simple. Clean. Closure. π
See also file:open.
π¦ file:open {#file:open} π¦
file:open $filename
Opens a file, bestie. But heads up: currently open only supports opening a file for reading β that's the whole menu right now, no writing, no appending, nothing extra. π
And not me reminding you that the file must be closed with close explicitly β it will not do it for you, no auto-cleanup, no vibes-based garbage collection. π
Example, because seeing it is believing:
~> cat a.txt
This is
a file.
~> use file
~> f = (file:open a.txt)
~> cat < $f
This is
a file.
~> close $f
See also file:close.
π§ file:pipe {#file:pipe} π§
file:pipe
Creates a brand new pipe that you can use in redirections. A pipe's got two ends, iconic duo behavior: a read-end and a write-end. And every pipe object is a pseudo-map with these fields:
rβ the read-end file object πwβ the write-end βοΈ
So when you redirect command input from a pipe with <, it's the read-end that gets used. When you redirect command output to a pipe with >, it's the write-end that gets used. And redirecting both input and output with <> to a pipe? Not supported. Don't try it, it's giving broken. π
Pipes have an OS-dependent buffer, so writing to a pipe without an active reader does not necessarily block β it might just vibe on through. And pipes must be explicitly closed with file:close. Periodt.
Also, putting values into pipes will cause those values to be discarded. Gone. Poof. They do not pass go. π
Examples (assuming the pipe has a large enough buffer):
~> p = (file:pipe)
~> echo 'lorem ipsum' > $p
~> head -n1 < $p
lorem ipsum
~> put 'lorem ipsum' > $p
~> file:close $p[w] # close the write-end
~> head -n1 < $p # blocks unless the write-end is closed
~> file:close $p[r] # close the read-end
See also file:close.
β file:truncate {#file:truncate} β
file:truncate $filename $size
Changes the size of the named file. And if that file is a symbolic link? Then it changes the size of the link's target, not the link itself β iykyk. π
The size has to be an integer between 0 and 2^64-1. That's the range. Respect it. π
And that's the whole page, bestie!! This was Elvish 0.17.0, dated Nov 18, 2024 β go forth and manipulate those file objects responsibly, mwah π β¨π«Ά
π¦ where this page comes from
- ubuntu jammy: elvish 0.17.0-1ubuntu0.1 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms