blob: cc416011fc2a13113bd10926f9b7f0bb8622bca9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 expand_path(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
|