From 89918c817d5296099778c9c381dfca13ef779db7 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 10 Oct 2019 22:55:42 +0200 Subject: [PATCH] Use UTF-8 on Windows to read directory entries Fixes #316 --- lib/colorls/core.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/colorls/core.rb b/lib/colorls/core.rb index b7d0eb6a..18cd531a 100644 --- a/lib/colorls/core.rb +++ b/lib/colorls/core.rb @@ -55,6 +55,15 @@ def ls private + @@encoding = begin # rubocop:disable Style/ClassVars + if ENV['OS'] == 'Windows_NT' && RUBY_PLATFORM !~ /cygwin/ + # use UTF-8 to read entries of directories on windows + Encoding::UTF_8 + else + Encoding.find('filesystem') + end + end + def init_colors(colors) @colors = colors @modes = Hash.new do |hash, key| @@ -79,7 +88,7 @@ def init_contents(path) info = FileInfo.new(path, link_info = @long) if info.directory? - @contents = Dir.entries(path) + @contents = Dir.entries(path, encoding: @@encoding) filter_hidden_contents