Permalink
Browse files

Add -a Option to list.lua

This PR simple adds a -a Option to list.lua which allows you to see hidden Files, even if the list.show_hidden setting is false.
  • Loading branch information...
Wilma456 committed Dec 4, 2017
1 parent 19e4c03 commit a335dd5caf903273362287d383dd3ec9e960f342
Showing with 10 additions and 3 deletions.
  1. +10 −3 src/main/resources/assets/computercraft/lua/rom/programs/list.lua
@@ -3,7 +3,14 @@ local tArgs = { ... }
-- Get all the files in the directory
local sDir = shell.dir()
if tArgs[1] ~= nil then

This comment has been minimized.

@SquidDev

SquidDev Dec 4, 2017

Contributor

I feel it'd be good to support ls foo -a as well. Maybe do something like

local sDir = shell.dir()
local bShowHiddenOption = false
for i = 1, #tArgs do
  if tArgs[i] == "-a" then
    bShowHiddenOption = true
  else
    sDir = tArgs[i]
  end
end
local bShowHiddenOption
if tArgs[1] == "-a" then
bShowHiddenOption = true
if tArgs[2] ~= nil then
sDir = shell.resolve( tArgs[2] )
end
elseif tArgs[1] ~= nil then
sDir = shell.resolve( tArgs[1] )
end
@@ -17,9 +24,9 @@ local tAll = fs.list( sDir )
local tFiles = {}
local tDirs = {}
local bShowHidden = settings.get( "list.show_hidden" )
local bShowHiddenSetting = settings.get( "list.show_hidden" )
for n, sItem in pairs( tAll ) do
if bShowHidden or string.sub( sItem, 1, 1 ) ~= "." then
if bShowHiddenSetting or string.sub( sItem, 1, 1 ) ~= "." or bShowHiddenOption then

This comment has been minimized.

@KnightMiner

KnightMiner Dec 4, 2017

This is minor, but bShowHiddenOption should be before the string.sub as it's the faster condition (shortcircuiting will mean we never need the strong.sub call then)

local sPath = fs.combine( sDir, sItem )
if fs.isDir( sPath ) then
table.insert( tDirs, sItem )

0 comments on commit a335dd5

Please sign in to comment.