-l
This commit is contained in:
parent
57987dc445
commit
b6220c85c4
2 changed files with 51 additions and 3 deletions
24
ls.rb
24
ls.rb
|
@ -5,6 +5,24 @@ require 'etc'
|
|||
|
||||
COLUMNS = 3
|
||||
MARGIN = 3
|
||||
PERMISSION = {
|
||||
'0' => '---',
|
||||
'1' => '--x',
|
||||
'2' => '-w-',
|
||||
'3' => '-wx',
|
||||
'4' => 'r--',
|
||||
'5' => 'r-x',
|
||||
'6' => 'rw-',
|
||||
'7' => 'rwx'
|
||||
}.freeze
|
||||
FILETYPE = {
|
||||
'1' => 'p',
|
||||
'2' => 'c',
|
||||
'4' => 'd',
|
||||
'6' => 'b',
|
||||
'10' => '-',
|
||||
'12' => 'l'
|
||||
}.freeze
|
||||
|
||||
def run
|
||||
listed_filenames = list_filenames
|
||||
|
@ -17,9 +35,9 @@ def list_filenames
|
|||
params = ARGV.getopts('a', 'r', 'l')
|
||||
filenames = params['a'] ? Dir.glob('*', File::FNM_DOTMATCH) : Dir.glob('*')
|
||||
filenames = filenames.reverse if params['r']
|
||||
params['l'] ? ownerinfo(filenames) : filenames
|
||||
if params['r']
|
||||
filenames.reverse
|
||||
if params['l']
|
||||
ownerinfo(filenames)
|
||||
exit
|
||||
else
|
||||
filenames
|
||||
end
|
||||
|
|
30
ls2.rb
Normal file
30
ls2.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'optparse'
|
||||
require 'etc'
|
||||
|
||||
NUMBER_OF_COLUMNS = 3
|
||||
COLUMN_MARGIN = 3
|
||||
SIZE_INDENT = 2
|
||||
|
||||
def main
|
||||
files = Dir.glob('*').sort
|
||||
output_ls(files)
|
||||
end
|
||||
|
||||
def output_ls(files)
|
||||
number_of_row = (files.size / NUMBER_OF_COLUMNS.to_f)
|
||||
max_lengths = make_max_lengths(files, number_of_row)
|
||||
|
||||
(0...number_of_row).each do |row|
|
||||
NUMBER_OF_COLUMNS.times do |column|
|
||||
index = row + column * number_of_row
|
||||
print files[index].ljust(max_lengths[column] + COLUMN_MARGIN) if files[index]
|
||||
end
|
||||
puts
|
||||
end
|
||||
end
|
||||
|
||||
def make_max_lengths(files, number_of_row)
|
||||
files.each_slice(number_of_row).to_a.map { _1.map(&:length).max }
|
||||
end
|
||||
|
||||
main
|
Loading…
Reference in a new issue