permission

This commit is contained in:
Rikuoh Tsujitani 2024-05-07 21:56:32 +09:00
parent 48e32d011a
commit b3000625fd
Signed by: riq0h
GPG key ID: 010F09DEA298C717

29
ls.rb
View file

@ -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