permission
This commit is contained in:
parent
48e32d011a
commit
b3000625fd
1 changed files with 23 additions and 6 deletions
29
ls.rb
29
ls.rb
|
@ -5,20 +5,37 @@ require 'optparse'
|
|||
COLUMNS = 3
|
||||
|
||||
def run
|
||||
listed_filenames = option_filenames
|
||||
listed_filenames = list_filenames
|
||||
filenames_matrix = slice_filenames(listed_filenames)
|
||||
filled_filenames = fill_filenames(filenames_matrix)
|
||||
arrange_filenames(filled_filenames)
|
||||
end
|
||||
|
||||
def option_filenames
|
||||
params = ARGV.getopts('a', 'r')
|
||||
def list_filenames
|
||||
params = ARGV.getopts('a', 'r', 'l')
|
||||
flags = params['a'] ? File::FNM_DOTMATCH : 0
|
||||
listing = Dir.glob('*', flags)
|
||||
params['l'] ? option_l : 0
|
||||
filenames = Dir.glob('*', flags)
|
||||
if params['r']
|
||||
listing.reverse
|
||||
filenames.reverse
|
||||
else
|
||||
listing
|
||||
filenames
|
||||
end
|
||||
end
|
||||
|
||||
def permission
|
||||
list_filenames.each do |index|
|
||||
file_stat = File::Stat.new
|
||||
case file_stat.mode.to_s(8)[index]
|
||||
when '0' then print '---'
|
||||
when '1' then print '--x'
|
||||
when '2' then print '-w-'
|
||||
when '3' then print '-wx'
|
||||
when '4' then print 'r--'
|
||||
when '5' then print 'r-x'
|
||||
when '6' then print 'rw-'
|
||||
when '7' then print 'rwx'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue