Merge pull request #164 from avdv/collation

Proper sorting according to current LANG / locale
This commit is contained in:
Athitya Kumar 2017-12-01 18:00:52 +05:30 committed by GitHub
commit 3af19cc54a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 2 deletions

View file

@ -17,7 +17,7 @@ file 'man/colorls.1' => ['man/colorls.1.ronn', 'lib/colorls/flags.rb'] do
flags = ColorLS::Flags.new
attributes = {
date: Time.now,
date: Date.iso8601(`git log -1 --pretty=format:%aI -- man/colorls.1`),
manual: 'colorls Manual',
organization: "colorls #{ColorLS::VERSION}"
}

View file

@ -43,6 +43,7 @@ Gem::Specification.new do |spec|
spec.post_install_message = ColorLS::POST_INSTALL_MESSAGE
spec.add_runtime_dependency 'clocale'
spec.add_runtime_dependency 'filesize'
spec.add_runtime_dependency 'manpages'
spec.add_runtime_dependency 'rainbow'

View file

@ -1,5 +1,6 @@
#!/usr/bin/env ruby
require 'colorls'
ColorLS::Flags.new(*ARGV).process
true

View file

@ -2,6 +2,7 @@ require 'yaml'
require 'etc'
require 'filesize'
require 'rainbow/ext/string'
require 'clocale'
require 'colorls/core'
require 'colorls/flags'

View file

@ -117,7 +117,7 @@ module ColorLS
when :size
@contents.sort_by! { |a| -File.size(File.join(path, a)) }
else
@contents.sort! { |a, b| a.casecmp(b) }
@contents.sort_by! { |a| CLocale.strxfrm(a) }
end
@contents.reverse! if @reverse
end

View file

@ -34,6 +34,9 @@ module ColorLS
end
def process
# initialize locale from environment
CLocale.setlocale(CLocale::LC_COLLATE, '')
return Core.new(@opts).ls if @args.empty?
@args.sort!.each_with_index do |path, i|
next STDERR.puts "\n Specified path '#{path}' doesn't exist.".colorize(:red) unless File.exist?(path)