Jump to content




lsa: List Advanced


14 replies to this topic

#1 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 21 May 2015 - 11:25 AM

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 by nitrogenfingers, 21 May 2015 - 11:49 AM.


#2 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 21 May 2015 - 11:47 AM

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 by nitrogenfingers, 21 May 2015 - 11:50 AM.


#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 21 May 2015 - 11:51 AM

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 by theoriginalbit, 21 May 2015 - 12:01 PM.


#4 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 21 May 2015 - 12: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!

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 21 May 2015 - 12:53 PM

View Postnitrogenfingers, on 21 May 2015 - 12:27 PM, said:

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

#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 21 May 2015 - 03:44 PM

...unless mounted in a writable mount.

#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 22 May 2015 - 12: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.

#8 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 22 May 2015 - 04:24 AM

I certainly don't have a clue, but to put my promoting hat back on, lsa can now tell you:

Posted Image

Of course the r is pretty superfluous but whatever.

#9 cyanisaac

  • Members
  • 369 posts
  • LocationSan Diego, CA

Posted 22 May 2015 - 04:54 AM

Looks cool, I will have to try this. And hey this looks cool you should make a video about it :P.

#10 superaxander

  • Members
  • 609 posts
  • LocationHolland

Posted 22 May 2015 - 06: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.

#11 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 23 May 2015 - 05:19 AM

What sized monitor are you having issues with?

#12 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 23 May 2015 - 05: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.

#13 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 23 May 2015 - 07: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 by nitrogenfingers, 23 May 2015 - 07:02 AM.


#14 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 23 May 2015 - 07:54 AM

View Postnitrogenfingers, on 23 May 2015 - 07:00 AM, said:

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.

View Postnitrogenfingers, on 23 May 2015 - 07:00 AM, said:

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 by theoriginalbit, 23 May 2015 - 07:56 AM.


#15 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 11 August 2015 - 08: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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users