This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
nitrogenfingers's profile picture

lsa: List Advanced

Started by nitrogenfingers, 21 May 2015 - 10:25 AM
nitrogenfingers #1
Posted 21 May 2015 - 12:25 PM
lsa: List Advanced


About

This is a small little utility program I designed to replace the in-built 'list' program because of two shortcomings; it doesn't show the size of files, and it doesn't show hidden files. Quite a few programs on the forums I've tried recently install hidden files onto your computer but unless you use fs.list explicitly, they're invisible to the user; so you either have to open up a terminal in your real computer and do a purge manually or cumbersomely do it with custom scripts or through the lua interpreter. Both solutions are ridiculous, so I made this tool to make the problem easier to deal with.

The other issue came when I accidentally hit the memory limit on my machine without realizing. fs.getFreeSpace makes it easy to know how much you have left, but knowing what's actually taking up that space is not so easy without, again, an external browser. This tool will report how big every file in the path is, and recursively calculate the total size of folders as well.

lsa on basic usage looks pretty-much identical to a regular ls call, and can be used perfectly safely as a substitute:
Spoiler

But we can use options to see a few hidden files from previous programs lurking on the hard drive. The long-list option also gives us an idea for how much space everything is taking up:
Spoiler

Like the built-in list, we can list multiple files and folders following those options:
Spoiler

Usage

You can download the script here: http://pastebin.com/fWDrjtvL

ls [option]… [path]…
-l: Uses long listing format, including file type and size
-a: List all files, including hidden files. This is equivalent to the -A (almost all) option in unix ls.
-h: Displays usage info

Options can be combined but you shouldn't put options after the path.

Comments

Like the built-in list, the program is reasonably useless unless it's in the system path. I have a dedicated folder for this (and other) utility program and a simple startup script to add them to the path, which is how I recommend you use it.

The biggest issue it has at the moment is it's quite slow when using the -l option; the recursive memory calculation can be slow on a system with a lot of files, and I haven't optimized the program very much. I'll keep toying and possibly make a few changes to get the speed up a bit. There is a tiny delay without the option as well, noticeable if you run them side-by-side.

Please leave comments if you have any questions, or find any issues with the tool. Thank you!
Edited on 21 May 2015 - 10:49 AM
nitrogenfingers #2
Posted 21 May 2015 - 12:47 PM
Premature launch! This only works in root at the moment. I've kept the download up but unless you're testing, I wouldn't get it. Mods feel free to lock until I get the issue resolved. Sorry all :(/>

Edit: Should be working now.
Edited on 21 May 2015 - 10:50 AM
theoriginalbit #3
Posted 21 May 2015 - 12:51 PM
Nice! I really like it :)/>

Does it have any custom display for read-only files? I think you should make dir and file the same length though, even just d and f would be fine it's slightly more intuitive than Un*x's d and -

Also have you considered making the ZSH of ComputerCraft? :P/>

EDIT: Locked by request
Edited on 21 May 2015 - 11:01 AM
nitrogenfingers #4
Posted 21 May 2015 - 01:27 PM
Thanks :)/> I did think about it, agonized over that for a bit really. There is a 'readonly' function I noticed but besides that CC lacks any real privilege system to make that the drwx listing necessary. Maybe a / in front of dir… I'll muse on it.

Haven't thought.. at all about ZSH :P/> Maybe when my thesis is done!
theoriginalbit #5
Posted 21 May 2015 - 01:53 PM
There is a 'readonly' function I noticed but besides that CC lacks any real privilege system to make that the drwx listing necessary. Maybe a / in front of dir… I'll muse on it.
Well any file that is mounted Java-side is read-only whether its the rom or its a folder added by a peripheral
Lyqyd #6
Posted 21 May 2015 - 04:44 PM
…unless mounted in a writable mount.
Bomb Bloke #7
Posted 22 May 2015 - 01:40 AM
Though I gather there are some funny cases. If memory serves, disk drives used to flag as "read only", and now don't. You can't delete/rename/whatever them either way, of course.
nitrogenfingers #8
Posted 22 May 2015 - 05:24 AM
I certainly don't have a clue, but to put my promoting hat back on, lsa can now tell you:



Of course the r is pretty superfluous but whatever.
cyanisaac #9
Posted 22 May 2015 - 05:54 AM
Looks cool, I will have to try this. And hey this looks cool you should make a video about it :P/>.
superaxander #10
Posted 22 May 2015 - 07:26 PM
I would like to suggest you add a -w <maximum width>. I prefer the file names not taking up the entire width of the screen.
nitrogenfingers #11
Posted 23 May 2015 - 06:19 AM
What sized monitor are you having issues with?
theoriginalbit #12
Posted 23 May 2015 - 06:53 AM
I must say that I am quite surprised you didn't make use of textutils.tabulate or textutils.pagedTabulate for the basic ls.
nitrogenfingers #13
Posted 23 May 2015 - 08:00 AM
Didn't even know they existed until you pointed them out… I haven't kept up with updates to the libraries I guess. Should do a proper flip-through of the wiki at some stage.

Edit: Looks like both are just slightly sub-optimal for my task, as colours vary by column rather than row.
Edited on 23 May 2015 - 06:02 AM
theoriginalbit #14
Posted 23 May 2015 - 08:54 AM
Didn't even know they existed until you pointed them out… I haven't kept up with updates to the libraries I guess. Should do a proper flip-through of the wiki at some stage.
Pretty sure they've been in for a very very long time :P/>

EDIT: okay so the change log definitely doesn't have when, though I'd assume they came in with Advanced Computers in CC 1.45 given their usage in the default list program.

Edit: Looks like both are just slightly sub-optimal for my task, as colours vary by column rather than row.
The default list program was able to use them just fine.
Edited on 23 May 2015 - 06:56 AM
nitrogenfingers #15
Posted 11 August 2015 - 09:45 AM
I came back to using this and found one or two odd bugs; turns out the paste was out of date! Should all be fixed now.

I didn't read tobit's comments carefully enough when I read this for some bizarre reason. I should have used tabulate but now I've done it the other way I'll stick with it, to keep it consistent with the long list function and to require fewer keystrokes to scroll. My bad though, sorry for not reading those more carefully!