Advertisement
rungholt

lsd

Mar 3rd, 2021
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. -- Get all the files in the directory
  4. local sDir = shell.dir()
  5. if tArgs[1] ~= nil then
  6.     sDir = shell.resolve(tArgs[1])
  7. end
  8.  
  9. if not fs.isDir(sDir) then
  10.     printError("Not a directory")
  11.     return
  12. end
  13.  
  14. -- Sort into dirs/files, and calculate column count
  15. local tAll = fs.list(sDir)
  16. local tFiles = {}
  17. local tDirs = {}
  18.  
  19. local bShowHidden = settings.get("list.show_hidden")
  20. for _, sItem in pairs(tAll) do
  21.     if bShowHidden or string.sub(sItem, 1, 1) ~= "." then
  22.         local sPath = fs.combine(sDir, sItem)
  23.         if fs.isDir(sPath) then
  24.             table.insert(tDirs, sItem)
  25.         end
  26.     end
  27. end
  28. table.sort(tDirs)
  29. table.sort(tFiles)
  30.  
  31. if term.isColour() then
  32.     textutils.pagedTabulate(colors.green, tDirs, colors.white, tFiles)
  33. else
  34.     textutils.pagedTabulate(tDirs, tFiles)
  35. end
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement