diff --git a/.rubocop.yml b/.rubocop.yml index 6e3c12c..f7f8d01 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -80,7 +80,7 @@ Style/MultilineBlockChain: # Current preferred metrics -------------------------------------------- # Better values are encouraged, but not required. Metrics/AbcSize: - Max: 20 + Max: 30 Metrics/MethodLength: Max: 20 @@ -88,6 +88,9 @@ Metrics/MethodLength: Metrics/CyclomaticComplexity: Max: 7 +Metrics/PerceivedComplexity: + Max: 8 + # TODO ----------------------------------------------------------------- Style/Documentation: diff --git a/colorls.gemspec b/colorls.gemspec index c3245d3..810ddcd 100644 --- a/colorls.gemspec +++ b/colorls.gemspec @@ -25,6 +25,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'facets' spec.add_runtime_dependency 'ruby-terminfo' spec.add_runtime_dependency 'filesize' + spec.add_runtime_dependency 'git' spec.add_development_dependency 'bundler', '~> 1.15' spec.add_development_dependency 'rake' diff --git a/lib/colorls.rb b/lib/colorls.rb index 46f32c5..75b18f4 100644 --- a/lib/colorls.rb +++ b/lib/colorls.rb @@ -4,6 +4,7 @@ require 'facets' require 'terminfo' require 'etc' require 'filesize' +require 'git' require 'colorls/core' require 'colorls/flags' diff --git a/lib/colorls/core.rb b/lib/colorls/core.rb index 636420f..2f78616 100644 --- a/lib/colorls/core.rb +++ b/lib/colorls/core.rb @@ -219,33 +219,25 @@ module ColorLS end def git_info(path,content) - require 'git' - while(!File.exist?(".git")) #check whether the repository is git controlled - if(Dir.pwd=="/") - return "" - end - Dir.chdir("..") + until File.exist?('.git') # check whether the repository is git controlled + return '' if Dir.pwd=='/' + Dir.chdir('..') end instance = Git.open '.' a = instance.status.added.keys # Added files u = instance.status.untracked.keys # Untracked files c = instance.status.changed.keys # Changed files p = path - p.slice! Dir.pwd+"/" - if(p==path) - p="" + p.slice! Dir.pwd+'/' + if p==path + p='' else - p=p+"/" - end - if a.any? {|x| x.include? "#{p}#{content}"} - return 'A' - elsif u.any? {|x| x.include? "#{p}#{content}"} - return 'U' - elsif c.any? {|x| x.include? "#{p}#{content}"} - return 'C' - else - return '-' + p+='/' end + return 'A' if a.any? { |x| x.include? "#{p}#{content}" } + return 'U' if u.any? { |x| x.include? "#{p}#{content}" } + return 'C' if c.any? { |x| x.include? "#{p}#{content}" } + p = '-' end def long_info(path, content) @@ -254,7 +246,8 @@ module ColorLS return '[No Info]'.colorize(@colors[:error]) + ' ' * (39 + @userlength + @grouplength) end stat = File.stat("#{path}/#{content}") - [mode_info(stat), user_info(stat), group_info(stat), size_info(stat), mtime_info(stat),git_info(path,content)].join(' ') + [mode_info(stat), user_info(stat), group_info(stat), size_info(stat), mtime_info(stat), + git_info(path,content)].join(' ') end def symlink_info(path, content)