sl3dge [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=106018 ls -al or ll <p>Hello everyone,</p> <p>Here's my first upload to the BBS ever, it's a simple rewrite of the <code>ls.lua</code> util. I've always preferred using <code>ls -al</code> (that is usually aliased as <code>ll</code>) in my unix terminals and because the muscle memory is too strong, I've just remade it quickly in Picotron. </p> <p>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.</p> <p>Just copy this code in 'll.lua' in '/appdata/system/util'</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>function lpad(nb, str) local nb_to_add = nb - #str local result = &quot;&quot; for k=0,nb_to_add do result = result..&quot; &quot; end return result..str end cd(env().path) local path0 = env().argv[1] or &quot;.&quot; path = fullpath(path0) if (not path) then print(&quot;could not resolve path &quot;..tostr(path0)) exit(0) end local res=ls(path) if (not res) then print(&quot;could not find path &quot;..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..&quot;/&quot;..res[i]) local meta = fetch_metadata(res[i]) local modified = &quot;&quot; if meta != nil then if meta.modified != nil then modified = meta.modified end end add(sizes, tostring(size)) local s = #tostring(size) if (s &gt; max_size) max_size = s add(modifies, modified) local m = #modified if (m &gt; max_mod) max_mod = m add(names, res[i]) local sub_c = &quot;1&quot; if type == &quot;folder&quot; then sub_c = tostring(#ls(res[i])) end add(sub_count, sub_c) if (#sub_c &gt; max_sub) max_sub = #sub_c end -- print header? --[[ local header = &quot;&quot; header = header .. &quot;nb&quot; header = header .. lpad(max_size, &quot;size&quot;) header = header .. lpad(max_mod, &quot;modified&quot;) header = header .. &quot; name&quot; print(header) --]] for i=1,#res do local str=&quot;&quot; local col = &quot;6&quot; if (sub(names[i],-4)==&quot;.lua&quot;) then col=&quot;c&quot; end if (sub(names[i],-4)==&quot;.txt&quot;) then col=&quot;a&quot; end if (sub(names[i],-4)==&quot;.pod&quot;) then col=&quot;9&quot; end if (sub(names[i],-4)==&quot;.png&quot;) then col=&quot;b&quot; end if (sub(names[i],-4)==&quot;.p64&quot;) then col=&quot;s&quot; 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..&quot; \f&quot;..col..names[i] print(str) end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=146563 https://www.lexaloffle.com/bbs/?tid=146563 Mon, 13 Jan 2025 20:35:35 UTC