hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/gils/tree.rv
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-10-06 12:49:46 +0200
committerhachem <im@hachem.wtf>2026-10-06 12:49:46 +0200
commit5d4a723a5f157c0ed38a348099a600d1d21c3c2b (patch)
tree70e5fdf560a64cd0eb3a13d88ce046ddd29fd077 /gils/tree.rv
parent52dab7fc85d877e80e3032f0afabae906adebad8 (diff)
feat: gils core utils and other shit
Diffstat (limited to 'gils/tree.rv')
-rw-r--r--gils/tree.rv35
1 files changed, 35 insertions, 0 deletions
diff --git a/gils/tree.rv b/gils/tree.rv
new file mode 100644
index 0000000..b052adb
--- /dev/null
+++ b/gils/tree.rv
@@ -0,0 +1,35 @@
+# recursive directory listing.
+
+fn tree_walk(path, prefix) do
+ const items = fs:entries(path)
+ if items == :nil return :nil
+ for index in 0..items:len() do
+ const entry = items[index]
+ const last = index == items:len() - 1
+ let branch = "|-- "
+ if last do branch = "`-- " end # font doesnt support fancy ascii symbols
+ const slash = if entry.type == 2 "/" else ""
+ puts("#{prefix}#{branch}#{entry.name}#{slash}\n")
+ if entry.type == 2 do
+ const child = if path == "/" "/#{entry.name}" else "#{path}/#{entry.name}"
+ let indent = "| "
+ if last do indent = " " end
+ tree_walk(child, prefix ~ indent)
+ end
+ end
+end
+
+const context = env.ctx
+const target = if context.argv:len() > 1 abspath(context.argv[1]) else wd.path
+if (vfs_owns(target) and target != "/") do puts("tree: #{target}: virtual dir\n") end
+else if (target != "/" and fs:is_dir(target) == :false) do puts("tree: #{target}: not a directory\n") end
+else do
+ puts("#{target}\n")
+ tree_walk(target, "")
+ # /proc is the one thing not on disk so tack it on at root
+ if target == "/" do
+ puts("`-- proc/\n")
+ puts(" |-- uptime\n")
+ puts(" `-- meminfo\n")
+ end
+end