Log In  


Hello everyone,

Here's my first upload to the BBS ever, it's a simple rewrite of the ls.lua util. I've always preferred using ls -al (that is usually aliased as ll) in my unix terminals and because the muscle memory is too strong, I've just remade it quickly in Picotron.

Let me know if you have any issue. I also wanted to add the 'rwx' info just as a joke, but it crowded the output a bit too much.

Just copy this code in 'll.lua' in '/appdata/system/util'

function lpad(nb, str)
	local nb_to_add = nb - #str
	local result = ""
	for k=0,nb_to_add do
		result = result.." "
	end		
	return result..str
end

cd(env().path)

local path0 = env().argv[1] or "."
path = fullpath(path0)

if (not path) then
	print("could not resolve path "..tostr(path0))
	exit(0)
end

local res=ls(path)

if (not res) then
	print("could not find path "..tostr(res))
	exit(0)
end

local sizes = {}
local max_size = 0
local modifies = {}
local max_mod = 0
local names = {}
local sub_count = {}
local max_sub = 0

for i=1,#res do
	local type, size, mount_point = fstat(path.."/"..res[i])
	local meta = fetch_metadata(res[i])
	local modified = ""
	if meta != nil then
		if meta.modified != nil then
			modified = meta.modified
		end
	end
	add(sizes, tostring(size))
	local s = #tostring(size)
	if (s > max_size) max_size = s
	add(modifies, modified)
	local m = #modified
	if (m > max_mod) max_mod = m
	add(names, res[i])

	local sub_c = "1"
	if type == "folder" then
		sub_c = tostring(#ls(res[i]))
	end
	add(sub_count, sub_c)
	if (#sub_c > max_sub) max_sub = #sub_c
end

-- print header?
--[[
local header = ""
header = header .. "nb"
header = header .. lpad(max_size, "size")
header = header .. lpad(max_mod, "modified")
header = header .. " name"
print(header)
--]]

for i=1,#res do
	local str=""
	local col = "6"

	if (sub(names[i],-4)==".lua") then col="c" end
	if (sub(names[i],-4)==".txt") then col="a" end
	if (sub(names[i],-4)==".pod") then col="9" end
	if (sub(names[i],-4)==".png") then col="b" end
	if (sub(names[i],-4)==".p64") then col="s" end

	str = str..lpad(max_sub, sub_count[i])	
	str = str..lpad(max_size, tostring(sizes[i]))
	str = str..lpad(max_mod, modifies[i])
	str = str.." \f"..col..names[i]

	print(str)
end
1



[Please log in to post a comment]