colorls 1.1.1 → 1.1.2.pre.557

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8c4e2dd3d9823e5c27fe6a41124dfc6511320df5
4
- data.tar.gz: 6ec38c1e754d1435363e03c4f86a6533e062f408
2
+ SHA256:
3
+ metadata.gz: ed1767483b77510e8c8cc835d5473bd292bf89a6cacf40e6102888eb57564539
4
+ data.tar.gz: edb9edf997d588639534ec82bdc22339fabd55402761f44f2bbdce2beea36a7e
5
5
  SHA512:
6
- metadata.gz: 74cca11860e9251eb41d953f0d98fb40f7b8e0b9ad189c9b1a4c258a277cc4d9849a5c361b80e36d86255ad72d3f6f6a08aea980a97e5a9997096a7223cbcf1d
7
- data.tar.gz: 2c8cd7f0c111826a0a257b2122cdcceda32dc02c7dafcd880fa3f461a92e447368f02815a3c67ec9c9810718fe343e4c31473cd996848c3fa12d01841e6c1cb9
6
+ metadata.gz: 22f3b7dbbb858b6b9d4b6d18c1fc6113158f8bde7a9899959f5eb777b404ddd8ba5779428f64d981e95b14ebaf1e91facc13cae39008ccb6d7c2fc490a15af34
7
+ data.tar.gz: be6c052a532e51b2b45059f2c6f3c6cb1c3fa015b5c3dae7810a248563d1531fb1f58ce34e6e736b3eb56680696e93d610e7325d167c2ff643d98defb0ca10ce
@@ -8,7 +8,7 @@ AllCops:
8
8
  - 'lib/yaml/*'
9
9
  - 'lib/**/*.sh'
10
10
  DisplayCopNames: true
11
- TargetRubyVersion: 2.1
11
+ TargetRubyVersion: 2.3
12
12
 
13
13
  # Preferred codebase style ---------------------------------------------
14
14
 
@@ -1,17 +1,30 @@
1
+ conditions: v1
2
+
3
+ if: branch = master OR tag IS present
4
+
1
5
  language:
2
6
  ruby
3
7
 
8
+ cache:
9
+ bundler
10
+
4
11
  rvm:
5
- - '2.1'
6
- - '2.2'
7
- - '2.3.0'
8
- - '2.4.0'
9
- - '2.5.0'
12
+ - '2.3'
13
+ - '2.4'
14
+ - '2.5'
15
+ - '2.6'
16
+
17
+ before_install:
18
+ - gem update --system
19
+ - gem --version
20
+ - gem install bundler -v '~> 2'
10
21
 
11
22
  script:
12
23
  - bundle exec rubocop
13
- - bundle exec rspec
14
- - rake install
24
+ - bundle exec rake spec
25
+ - bundle exec rake install
26
+ - bundle binstubs colorls
27
+ - PATH=$PWD/bin:$PATH
15
28
  - colorls
16
29
  - colorls -1
17
30
  - colorls -a
@@ -25,6 +38,7 @@ script:
25
38
  - colorls -r
26
39
  - colorls --sd
27
40
  - colorls --sf
41
+ - colorls --hyperlink
28
42
  - colorls -t
29
43
  - colorls --sort=time
30
44
  - colorls -U
@@ -37,7 +51,19 @@ script:
37
51
  - colorls README.md
38
52
  - colorls *
39
53
  - colorls | grep /
54
+ - colorls --color
55
+ - colorls --color=auto
56
+ - colorls --color=never
57
+ - colorls --color=always
58
+ - colorls --tree
59
+ - colorls --tree=1
40
60
 
41
- install:
42
- - gem install bundler
43
- - bundle install
61
+ deploy:
62
+ provider: rubygems
63
+ api_key:
64
+ secure: iHo85pvy3iIp0/r8mbP0q0VPCFyYcwaQb19YUxwIGbMrksswIJPe2bsdAQTvd1fU3U+uwAgyzfaLMWgY6T1evVjv5GGXW0zmNthgWuaCbTBmzx3q6OPV6zJLsinKSJ4xbKjmTOi6BIhXTtc09dRRNp1d9U8HtmM9KyvD5ORm5M9W0/WxP3+8oOe0/yl3DOVNgCQ0j64KEqowLlfdJXe2q5iSUkZEvf+o5F6pz0g7dFiVHPVpJbZ9sOchPzYNMjLCx4jPt42J806oAH7TMeRC4lFpKgJr9U05LRGb22jiokHH6gl17RpuGRYJIexWkf3jb5iy9bivT2S2fGo9/BBKO5BvQAaL7McCwpdKM2QEyVy7RVbUz5D8vfXkJNIJankQj3Ikuz7qYyDglucGCpSGjecNCqL61NoBag7ORJ0RMWg7zklKjR59zeT4oks8rByx688y5Oi4f9Z98SPfc9NIJbHxbrDHtr13gm509cEXxwOLuVePa9J+mDGq2Uawi/PuIon1x2ztHUgvTx0DSYtwv96HzXet8QqXHwRKKjddxEApvCvGvaJV3akeUVjcsyei892ajHP6CffaKazPtogotfsu68g8WmKFWHFRkdmS6NIqg7MrnMRCjDkxAoQYYzt6cl95aBk4G7CTbjtXgIct1LGMM/WjE6K/jpeF0YLsVR4=
65
+ gem: colorls
66
+ on:
67
+ repo: athityakumar/colorls
68
+ rvm: '2.6'
69
+ os: linux
@@ -0,0 +1,81 @@
1
+ Color LS contributors (sorted alphabetically)
2
+ ============================================
3
+
4
+ * **[Ace Dimasuhid](https://github.com/adimasuhid)**
5
+
6
+ * **[Adnan](https://github.com/udnaan)**
7
+
8
+ * **[Alex Johnson](https://github.com/alexpjohnson)**
9
+
10
+ * **[Alexander Arvidsson](https://github.com/Metamist)**
11
+
12
+ * **[Andy](https://github.com/acarl005)**
13
+
14
+ * **[Anthony Jean](https://github.com/lewazo)**
15
+
16
+ * **[Athitya Kumar](https://github.com/athityakumar)**
17
+
18
+ * **[Balaji Ravichandran](https://github.com/balogic)**
19
+
20
+ * **[Claudio Bley](https://github.com/avdv)**
21
+
22
+ * **[Eric Soldierer](https://github.com/EricSoldierer)**
23
+
24
+ * **[Fatih Erikli](https://github.com/fatiherikli)**
25
+
26
+ * **[Gary Traffanstedt](https://github.com/blimey85)**
27
+
28
+ * **[Henré Botha](https://github.com/henrebotha)**
29
+
30
+ * **[hirowatari](https://github.com/hirowatari)**
31
+
32
+ * **[Igor Souza](https://github.com/igordcsouza)**
33
+
34
+ * **[Kaustubh Hiware](https://github.com/kaustubhhiware)**
35
+
36
+ * **[Khải](https://github.com/KSXGitHub)**
37
+
38
+ * **[Liam Hockley](https://github.com/xdega)**
39
+
40
+ * **[Mamonu](https://github.com/mamonu)**
41
+
42
+ * **[Mariel Frank](https://github.com/marielfrank)**
43
+
44
+ * **[mashehu](https://github.com/mashehu)**
45
+
46
+ * **[Matthew Vincent](https://github.com/neshmi)**
47
+
48
+ * **[Michael](https://github.com/mscottnelson)**
49
+
50
+ * **[Michael Dungan](https://github.com/xxx)**
51
+
52
+ * **[Michael McMahon](https://github.com/TechnologyClassroom)**
53
+
54
+ * **[Oskar](https://github.com/GladOSkar)**
55
+
56
+ * **[Paulo](https://github.com/redcinelli)**
57
+
58
+ * **[Pranit Bauva](https://github.com/pranitbauva1997)**
59
+
60
+ * **[Rohit Ner](https://github.com/rohitner)**
61
+
62
+ * **[Ryan L McIntyre](https://github.com/ryanoasis)**
63
+
64
+ * **[Sam Lazarus](https://github.com/sl)**
65
+
66
+ * **[Sam Umbach](https://github.com/sumbach)**
67
+
68
+ * **[sergeant-wizard](https://github.com/sergeant-wizard)**
69
+
70
+ * **[Stephen Wentling](https://github.com/swentling87)**
71
+
72
+ * **[Tom Lazar](https://github.com/tomlazar)**
73
+
74
+ * **[Tomasz](https://github.com/rubikonx9)**
75
+
76
+ * **[Vincent](https://github.com/trivett)**
77
+
78
+ * **[Vladislav Isakov](https://github.com/bladebhs)**
79
+
80
+
81
+ **[Full contributors list](https://github.com/athityakumar/colorls/graphs/contributors).**
data/README.md CHANGED
@@ -26,10 +26,11 @@ A Ruby script that colorizes the `ls` output with color and icons. Here are the
26
26
  - `-h` (or) `--help`
27
27
  - `-l` (or) `--long`
28
28
  - `-r` (or) `--report`
29
- - `-t` (or) `--tree`
29
+ - `--tree` (or) `--tree=[DEPTH]`
30
30
  - `--gs` (or) `--git-status`
31
31
  - `--sd` (or) `--sort-dirs` or `--group-directories-first`
32
32
  - `--sf` (or) `--sort-files`
33
+ - `-t`
33
34
  - [Combination of flags](#combination-of-flags)
34
35
  - [Installation](#installation)
35
36
  - [Recommended configurations](#recommended-configurations)
@@ -79,7 +80,7 @@ Man pages have been added. Checkout `man colorls`.
79
80
 
80
81
  ![image](https://user-images.githubusercontent.com/17109060/32149082-96a83fec-bd25-11e7-9081-7f77e4c90e90.png)
81
82
 
82
- - With `-t` (or) `--tree` : Shows tree view of the directory
83
+ - With `--tree` (or) `--tree=[DEPTH]` : Shows tree view of the directory with the specified depth (default 3)
83
84
 
84
85
  ![image](https://user-images.githubusercontent.com/17109060/32149051-32e596e4-bd25-11e7-93a9-5e50c8d2bb19.png)
85
86
 
@@ -95,6 +96,8 @@ Man pages have been added. Checkout `man colorls`.
95
96
 
96
97
  ![image](https://user-images.githubusercontent.com/17109060/32149071-6b379de4-bd25-11e7-8764-a0c577e526a1.png)
97
98
 
99
+ - With `-t` : Sort by modification time, newest first (NEED TO ADD IMAGE)
100
+
98
101
  - With color options : `--light` or `--dark` can be passed as a flag, to choose the appropriate color scheme. By default, the dark color scheme is chosen. In order to tweak any color, read [Custom configurations](#custom-configurations).
99
102
 
100
103
  ### Combination of flags
@@ -118,7 +121,7 @@ Man pages have been added. Checkout `man colorls`.
118
121
  1. Install Ruby (preferably, version > 2.1)
119
122
  2. Install the patched fonts of powerline nerd-font and/or font-awesome. Have a look at the [Nerd Font README](https://github.com/ryanoasis/nerd-fonts/blob/master/readme.md) for more installation instructions.
120
123
 
121
- *Note for `iTerm2` users - Please enable the Nerd Font at iTerm2 > Preferences > Profiles > Text > Non-ASCII font > Knack Regular Nerd Font Complete.*
124
+ *Note for `iTerm2` users - Please enable the Nerd Font at iTerm2 > Preferences > Profiles > Text > Non-ASCII font > Hack Regular Nerd Font Complete.*
122
125
 
123
126
  3. Install the [colorls](https://rubygems.org/gems/colorls/) ruby gem with `gem install colorls`
124
127
 
@@ -188,6 +191,11 @@ You can overwrite the existing icons and colors mapping by copying the yaml file
188
191
  swift: "\uF179"
189
192
  ```
190
193
 
194
+ - User contributed alias configurations :
195
+
196
+ - [@rjhilgefort](https://gist.github.com/rjhilgefort/51ea47dd91bcd90cd6d9b3b199188c16)
197
+
198
+
191
199
  # Updating
192
200
 
193
201
  [(Back to top)](#table-of-contents)
data/Rakefile CHANGED
@@ -3,7 +3,9 @@ require 'rubygems/tasks'
3
3
  Gem::Tasks.new
4
4
 
5
5
  require 'rspec/core/rake_task'
6
- RSpec::Core::RakeTask.new
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.rspec_opts = "--warnings"
8
+ end
7
9
 
8
10
  require 'rubocop/rake_task'
9
11
  RuboCop::RakeTask.new do |task|
@@ -13,6 +15,7 @@ end
13
15
  desc 'Build the manual'
14
16
  file 'man/colorls.1' => ['man/colorls.1.ronn', 'lib/colorls/flags.rb'] do
15
17
  require 'colorls'
18
+ require 'date'
16
19
  require 'ronn'
17
20
 
18
21
  flags = ColorLS::Flags.new
@@ -2,7 +2,7 @@ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'colorls/version'
4
4
 
5
- ColorLS::POST_INSTALL_MESSAGE = %(
5
+ POST_INSTALL_MESSAGE = %(
6
6
  *******************************************************************
7
7
  Changes introduced in colorls
8
8
 
@@ -25,14 +25,28 @@ ColorLS::POST_INSTALL_MESSAGE = %(
25
25
 
26
26
  # rubocop:disable Metrics/BlockLength
27
27
  Gem::Specification.new do |spec|
28
+ is_tagged = ENV['TRAVIS_TAG'] == "v#{ColorLS::VERSION}"
29
+ is_origin = ENV['TRAVIS_REPO_SLUG'] == 'athityakumar/colorls'
30
+ build_number = ENV['TRAVIS_BUILD_NUMBER']
31
+
28
32
  spec.name = 'colorls'
29
- spec.version = ColorLS::VERSION
33
+ spec.version = if build_number && is_origin && !is_tagged
34
+ # Prereleasing on Travis CI
35
+ digits = ColorLS::VERSION.to_s.split '.'
36
+ digits[-1] = digits[-1].to_s.succ
37
+
38
+ digits.join('.') + ".pre.#{build_number}"
39
+ else
40
+ ColorLS::VERSION
41
+ end
30
42
  spec.authors = ['Athitya Kumar']
31
43
  spec.email = ['athityakumar@gmail.com']
32
44
  spec.summary = "A Ruby CLI gem that beautifies the terminal's ls command, with color and font-awesome icons."
33
45
  spec.homepage = 'https://github.com/athityakumar/colorls'
34
46
  spec.license = 'MIT'
35
47
 
48
+ spec.required_ruby_version = '>= 2.3.0'
49
+
36
50
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
37
51
  f.match(%r{^(test|spec|features)/})
38
52
  end
@@ -41,22 +55,24 @@ Gem::Specification.new do |spec|
41
55
  spec.executables = 'colorls'
42
56
  spec.require_paths = ['lib']
43
57
 
44
- spec.post_install_message = ColorLS::POST_INSTALL_MESSAGE
45
-
46
- spec.add_runtime_dependency 'clocale'
47
- spec.add_runtime_dependency 'filesize'
48
- spec.add_runtime_dependency 'manpages'
49
- spec.add_runtime_dependency 'rainbow'
50
-
51
- spec.add_development_dependency 'bundler', '~> 1.15'
52
- spec.add_development_dependency 'diffy'
53
- spec.add_development_dependency 'rake'
54
- spec.add_development_dependency 'ronn'
55
- spec.add_development_dependency 'rspec'
56
- spec.add_development_dependency 'rspec-its'
57
- spec.add_development_dependency 'rubocop'
58
- spec.add_development_dependency 'rubocop-rspec'
59
- spec.add_development_dependency 'rubygems-tasks'
60
- spec.add_development_dependency 'simplecov'
58
+ spec.post_install_message = POST_INSTALL_MESSAGE
59
+
60
+ spec.add_runtime_dependency 'clocale', '~> 0'
61
+ spec.add_runtime_dependency 'filesize', '~> 0'
62
+ spec.add_runtime_dependency 'manpages', '~> 0'
63
+ spec.add_runtime_dependency 'rainbow', '>= 2.2', '< 4.0'
64
+
65
+ spec.add_development_dependency 'bundler', '~> 2.0'
66
+ spec.add_development_dependency 'codecov', '~> 0.1'
67
+ spec.add_development_dependency 'diffy', '~> 3'
68
+ spec.add_development_dependency 'rake', '~> 12'
69
+ spec.add_development_dependency 'rdoc', '~> 6.1'
70
+ spec.add_development_dependency 'ronn', '~> 0'
71
+ spec.add_development_dependency 'rspec', '~> 3.7'
72
+ spec.add_development_dependency 'rspec-its', '~> 1.2'
73
+ spec.add_development_dependency 'rubocop', '~> 0.65.0'
74
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.27'
75
+ spec.add_development_dependency 'rubygems-tasks', '~> 0'
76
+ spec.add_development_dependency 'simplecov', '~> 0.16.1'
61
77
  end
62
78
  # rubocop:enable Metrics/BlockLength
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'colorls'
4
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'etc'
3
5
  require 'English'
@@ -1,12 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ColorLS
2
4
  class Core
3
5
  def initialize(input, all: false, report: false, sort: false, show: false,
4
6
  mode: nil, git_status: false, almost_all: false, colors: [], group: nil,
5
- reverse: false)
7
+ reverse: false, hyperlink: false, tree_depth: nil)
6
8
  @input = File.absolute_path(input)
7
9
  @count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
8
10
  @all = all
9
11
  @almost_all = almost_all
12
+ @hyperlink = hyperlink
10
13
  @report = report
11
14
  @sort = sort
12
15
  @reverse = reverse
@@ -14,13 +17,13 @@ module ColorLS
14
17
  @show = show
15
18
  @one_per_line = mode == :one_per_line
16
19
  @long = mode == :long
17
- @tree = mode == :tree
20
+ @tree = {mode: mode == :tree, depth: tree_depth}
18
21
  process_git_status_details(git_status)
19
22
 
20
23
  @screen_width = IO.console.winsize[1]
21
24
  @screen_width = 80 if @screen_width.zero?
22
25
 
23
- @colors = colors
26
+ init_colors colors
24
27
 
25
28
  @contents = init_contents(input)
26
29
  @max_widths = @contents.map { |c| c.name.length }
@@ -30,9 +33,9 @@ module ColorLS
30
33
  def ls
31
34
  return print "\n Nothing to show here\n".colorize(@colors[:empty]) if @contents.empty?
32
35
 
33
- if @tree
36
+ if @tree[:mode]
34
37
  print "\n"
35
- tree_traverse(@input, 0, 2)
38
+ tree_traverse(@input, 0, 1, 2)
36
39
  else
37
40
  @contents = chunkify
38
41
  @contents.each { |chunk| ls_line(chunk) }
@@ -43,6 +46,19 @@ module ColorLS
43
46
 
44
47
  private
45
48
 
49
+ def init_colors(colors)
50
+ @colors = colors
51
+ @modes = Hash.new do |hash, key|
52
+ color = case key
53
+ when 'r' then :read
54
+ when 'w' then :write
55
+ when '-' then :no_access
56
+ when 'x', 's', 'S', 't', 'T' then :exec
57
+ end
58
+ hash[key] = key.colorize(@colors[color]).freeze
59
+ end
60
+ end
61
+
46
62
  def init_contents(path)
47
63
  info = FileInfo.new(path, link_info = @long)
48
64
 
@@ -62,6 +78,7 @@ module ColorLS
62
78
  @total_content_length = @contents.length
63
79
 
64
80
  return @contents unless @long
81
+
65
82
  init_user_lengths
66
83
  init_group_lengths
67
84
  @contents
@@ -92,6 +109,13 @@ module ColorLS
92
109
 
93
110
  def sort_contents
94
111
  case @sort
112
+ when :extension
113
+ @contents.sort_by! do |f|
114
+ name = f.name
115
+ ext = File.extname(name)
116
+ name = name.chomp(ext) unless ext.empty?
117
+ [ext, name].map { |s| CLocale.strxfrm(s) }
118
+ end
95
119
  when :time
96
120
  @contents.sort_by! { |a| -a.mtime.to_f }
97
121
  when :size
@@ -118,14 +142,6 @@ module ColorLS
118
142
  @file_aliases = ColorLS::Yaml.new('file_aliases.yaml').load(aliase: true)
119
143
  @folders = ColorLS::Yaml.new('folders.yaml').load
120
144
  @folder_aliases = ColorLS::Yaml.new('folder_aliases.yaml').load(aliase: true)
121
-
122
- @file_keys = @files.keys
123
- @file_aliase_keys = @file_aliases.keys
124
- @folder_keys = @folders.keys
125
- @folder_aliase_keys = @folder_aliases.keys
126
-
127
- @all_files = @file_keys + @file_aliase_keys
128
- @all_folders = @folder_keys + @folder_aliase_keys
129
145
  end
130
146
 
131
147
  def chunkify
@@ -164,25 +180,28 @@ module ColorLS
164
180
  .colorize(@colors[:report])
165
181
  end
166
182
 
183
+ def format_mode(rwx, special, char)
184
+ m_r = (rwx & 4).zero? ? '-' : 'r'
185
+ m_w = (rwx & 2).zero? ? '-' : 'w'
186
+ m_x = if special
187
+ (rwx & 1).zero? ? char.upcase : char
188
+ else
189
+ (rwx & 1).zero? ? '-' : 'x'
190
+ end
191
+
192
+ @modes[m_r] + @modes[m_w] + @modes[m_x]
193
+ end
194
+
167
195
  def mode_info(stat)
168
- mode = ''
169
- stat.mode.to_s(2).rjust(16, '0')[-9..-1].each_char.with_index do |c, i|
170
- if c == '0'
171
- mode += '-'.colorize(@colors[:no_access])
172
- else
173
- case (i % 3)
174
- when 0 then mode += 'r'.colorize(@colors[:read])
175
- when 1 then mode += 'w'.colorize(@colors[:write])
176
- when 2 then mode += 'x'.colorize(@colors[:exec])
177
- end
178
- end
179
- end
180
- mode
196
+ m = stat.mode
197
+
198
+ format_mode(m >> 6, stat.setuid?, 's') +
199
+ format_mode(m >> 3, stat.setgid?, 's') +
200
+ format_mode(m, stat.sticky?, 't')
181
201
  end
182
202
 
183
203
  def user_info(content)
184
- user = content.owner.ljust(@userlength, ' ')
185
- user.colorize(@colors[:user]) if content.owned?
204
+ content.owner.ljust(@userlength, ' ').colorize(@colors[:user])
186
205
  end
187
206
 
188
207
  def group_info(group)
@@ -191,9 +210,10 @@ module ColorLS
191
210
 
192
211
  def size_info(filesize)
193
212
  size = Filesize.from("#{filesize} B").pretty.split(' ')
194
- size = "#{size[0][0..-4].rjust(3,' ')} #{size[1].ljust(3,' ')}"
213
+ size = "#{size[0][0..-4].rjust(4,' ')} #{size[1].ljust(3,' ')}"
195
214
  return size.colorize(@colors[:file_large]) if filesize >= 512 * 1024 ** 2
196
215
  return size.colorize(@colors[:file_medium]) if filesize >= 128 * 1024 ** 2
216
+
197
217
  size.colorize(@colors[:file_small])
198
218
  end
199
219
 
@@ -202,38 +222,31 @@ module ColorLS
202
222
  now = Time.now
203
223
  return mtime.colorize(@colors[:hour_old]) if now - file_mtime < 60 * 60
204
224
  return mtime.colorize(@colors[:day_old]) if now - file_mtime < 24 * 60 * 60
225
+
205
226
  mtime.colorize(@colors[:no_modifier])
206
227
  end
207
228
 
208
229
  def process_git_status_details(git_status)
209
- return false unless git_status
210
-
211
- @git_root_path = IO.popen(['git', '-C', @input, 'rev-parse', '--show-toplevel'], err: :close, &:gets)
212
-
213
- return false unless $CHILD_STATUS.success?
214
-
215
- @git_status = Git.status(@git_root_path.chomp!)
230
+ @git_status = case
231
+ when !git_status then nil
232
+ when File.directory?(@input) then Git.status(@input)
233
+ else Git.status(File.dirname(@input))
234
+ end
216
235
  end
217
236
 
218
- def git_info(path, content)
237
+ def git_info(content)
219
238
  return '' unless @git_status
220
239
 
221
- real_path = File.realdirpath(content.name, path)
222
-
223
- return ' ' unless real_path.start_with? path
224
-
225
- relative_path = real_path.remove(Regexp.new('^' + Regexp.escape(@git_root_path) + '/?'))
226
-
227
240
  if content.directory?
228
- git_dir_info(relative_path)
241
+ git_dir_info(content.name)
229
242
  else
230
- git_file_info(relative_path)
243
+ git_file_info(content.name)
231
244
  end
232
- # puts "\n\n"
233
245
  end
234
246
 
235
247
  def git_file_info(path)
236
248
  return ' ✓ '.colorize(@colors[:unchanged]) unless @git_status[path]
249
+
237
250
  Git.colored_status_symbols(@git_status[path].uniq, @colors)
238
251
  end
239
252
 
@@ -251,12 +264,14 @@ module ColorLS
251
264
 
252
265
  def long_info(content)
253
266
  return '' unless @long
267
+
254
268
  [mode_info(content.stats), user_info(content), group_info(content.group),
255
269
  size_info(content.size), mtime_info(content.mtime)].join(' ')
256
270
  end
257
271
 
258
272
  def symlink_info(content)
259
273
  return '' unless @long && content.symlink?
274
+
260
275
  link_info = " ⇒ #{content.link_target}"
261
276
  if content.dead?
262
277
  "#{link_info} [Dead link]".colorize(@colors[:dead_link])
@@ -273,12 +288,14 @@ module ColorLS
273
288
  @count[increment] += 1
274
289
  value = increment == :folders ? @folders[key] : @files[key]
275
290
  logo = value.gsub(/\\u[\da-f]{4}/i) { |m| [m[-4..-1].to_i(16)].pack('U') }
291
+ name = content.name
292
+ name = make_link(path, name) if @hyperlink
276
293
 
277
294
  [
278
295
  long_info(content),
279
- " #{git_info(path,content)} ",
296
+ " #{git_info(content)} ",
280
297
  logo.colorize(color),
281
- " #{content.name.colorize(color)}#{slash?(content)}#{symlink_info(content)}"
298
+ " #{name.colorize(color)}#{slash?(content)}#{symlink_info(content)}"
282
299
  ].join
283
300
  end
284
301
 
@@ -292,39 +309,60 @@ module ColorLS
292
309
  print "\n"
293
310
  end
294
311
 
312
+ def file_color(file, key)
313
+ color_key = case
314
+ when file.chardev? then :chardev
315
+ when file.blockdev? then :blockdev
316
+ when file.socket? then :socket
317
+ else
318
+ @files.key?(key) ? :recognized_file : :unrecognized_file
319
+ end
320
+ @colors[color_key]
321
+ end
322
+
295
323
  def options(content)
296
324
  if content.directory?
297
325
  key = content.name.to_sym
326
+ key = @folder_aliases[key] unless @folders.key? key
327
+ key = :folder if key.nil?
298
328
  color = @colors[:dir]
299
- return [:folder, color, :folders] unless @all_folders.include?(key)
300
- key = @folder_aliases[key] unless @folder_keys.include?(key)
301
- return [key, color, :folders]
329
+ group = :folders
330
+ else
331
+ key = content.name.split('.').last.downcase.to_sym
332
+ key = @file_aliases[key] unless @files.key? key
333
+ key = :file if key.nil?
334
+ color = file_color(content, key)
335
+ group = @files.key?(key) ? :recognized_files : :unrecognized_files
302
336
  end
303
337
 
304
- color = @colors[:recognized_file]
305
- return [content.downcase.to_sym, color, :recognized_files] if @file_keys.include?(key)
306
-
307
- key = content.name.split('.').last.downcase.to_sym
308
- return [:file, @colors[:unrecognized_file], :unrecognized_files] unless @all_files.include?(key)
309
-
310
- key = @file_aliases[key] unless @file_keys.include?(key)
311
- [key, color, :recognized_files]
338
+ [key, color, group]
312
339
  end
313
340
 
314
- def tree_traverse(path, prespace, indent)
341
+ def tree_traverse(path, prespace, depth, indent)
315
342
  contents = init_contents(path)
316
343
  contents.each do |content|
317
344
  icon = content == contents.last || content.directory? ? ' └──' : ' ├──'
318
345
  print tree_branch_preprint(prespace, indent, icon).colorize(@colors[:tree])
319
346
  print " #{fetch_string(path, content, *options(content))} \n"
320
347
  next unless content.directory?
321
- tree_traverse("#{path}/#{content}", prespace + indent, indent)
348
+
349
+ tree_traverse("#{path}/#{content}", prespace + indent, depth + 1, indent) if keep_going(depth)
322
350
  end
323
351
  end
324
352
 
353
+ def keep_going(depth)
354
+ @tree[:depth].nil? || depth < @tree[:depth]
355
+ end
356
+
325
357
  def tree_branch_preprint(prespace, indent, prespace_icon)
326
358
  return prespace_icon if prespace.zero?
359
+
327
360
  ' │ ' * (prespace/indent) + prespace_icon + '─' * indent
328
361
  end
362
+
363
+ def make_link(path, name)
364
+ href = "file://#{path}/#{name}"
365
+ "\033]8;;#{href}\007#{name}\033]8;;\007"
366
+ end
329
367
  end
330
368
  end