add support for --non-human-readable flag

This commit is contained in:
Ayush Poddar 2023-04-18 19:50:08 +05:30
parent 3ad436b533
commit e231708f30
2 changed files with 9 additions and 2 deletions

View file

@ -140,6 +140,7 @@ module ColorLS
@show_group = long_style_options.key?(:show_group) ? long_style_options[:show_group] : true
@show_user = long_style_options.key?(:show_user) ? long_style_options[:show_user] : true
@show_symbol_dest = long_style_options.key?(:show_symbol_dest) ? long_style_options[:show_symbol_dest] : false
@show_human_readable_size = long_style_options.key?(:human_readable_size) ? long_style_options[:human_readable_size] : true
end
def init_git_status(show_git)
@ -254,7 +255,9 @@ module ColorLS
end
def size_info(filesize)
size = Filesize.new(filesize).pretty.split
filesize = Filesize.new(filesize)
size = @show_human_readable_size ? filesize.pretty : filesize.to_s
size = size.split
size = "#{size[0][0..-4].rjust(4,' ')} #{size[1].ljust(3,' ')}"
return size.colorize(@colors[:file_large]) if filesize >= 512 * (1024 ** 2)
return size.colorize(@colors[:file_medium]) if filesize >= 128 * (1024 ** 2)

View file

@ -184,7 +184,8 @@ module ColorLS
show_user: true,
time_style: '',
hard_links_count: true,
show_symbol_dest: false
show_symbol_dest: false,
human_readable_size: true
}
end
@ -199,6 +200,9 @@ module ColorLS
long_style_options[:hard_links_count] = false
end
long_style_options = get_long_style_symlink_options(options, long_style_options)
options.on('--nh', '--non-human-readable', 'show file sizes in bytes only') do
long_style_options[:human_readable_size] = false
end
@opts[:long_style_options] = long_style_options
end