colorls/exe/lc

56 lines
1.3 KiB
Text
Raw Normal View History

2017-07-05 16:23:11 +02:00
#!/usr/bin/env ruby
require 'colorls'
args = *ARGV
opts = {}
opts[:report] = args.include?('-r') || args.include?('--report')
opts[:one_per_line] = args.include?('-1')
show_dirs_only = args.include?('-d') || args.include?('--dirs')
show_files_only = args.include?('-f') || args.include?('--files')
sort_dirs_first = args.include?('-sd') || args.include?('--sort-dirs')
sort_files_first = args.include?('-sf') || args.include?('--sort-files')
if sort_dirs_first && sort_files_first
STDERR.puts "\n Restrain from using -sd and -sf flags together."
.colorize(:red)
return
end
if show_files_only && show_dirs_only
STDERR.puts "\n Restrain from using -d and -f flags together."
.colorize(:red)
return
end
opts[:sort] = if sort_files_first
:files
elsif sort_dirs_first
:dirs
end
opts[:show] = if show_files_only
:files
elsif show_dirs_only
:dirs
end
args.keep_if { |arg| !arg.start_with?('-') }
if args.empty?
ColorLS.new(opts).ls
else
args.each do |path|
if Dir.exist?(path)
ColorLS.new(path, opts).ls
else
next STDERR.puts "\n Specified directory '#{path}' doesn't exist."
.colorize(:red)
end
end
end
true