colorls 1.0.8 → 1.0.9

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
2
  SHA1:
3
- metadata.gz: 7a905f2aeeb9c19d35ce0605e5b561ae05a811df
4
- data.tar.gz: a9a42dab47db4f9659a98c849e7d1cffa7981fd8
3
+ metadata.gz: f4071319ab261196949f1a3cf87ebe1c55d7582c
4
+ data.tar.gz: 40c07660304acb180e356b0bfaa4e7ecb6bbe2fc
5
5
  SHA512:
6
- metadata.gz: fb68576d3e09f608517f46e07f4c2ec5256e2bd1dc82524787d710c4353e3a290d1a1538ad16fb96573c69feb6274f506ad7990020f10700a7f01aed4c2a272f
7
- data.tar.gz: f31f376ceb1c0e9f94dc14e89114c27ff55c4de9ab8092067b864ff1c837ab191e395bba1cb7b5f1edd58ebe8dddd9bbe28eb3ca6cc47180b80fbf8e4ee3fda4
6
+ metadata.gz: fcacb48be3c568c7cc64815de3847c7b093950f4d834de0b55e9c969aaf791fa0d6fb7547bf347f7211872f5b9c14f035ae7044c64496d0a55c02a85c327cbed
7
+ data.tar.gz: edca7e18cef76348a81313431016de823b83b3f79d3579890db0bd0329605f53ee0c7e2c97a46fdfb9b9873e2a5c674801c5d03eba8e6dda2302bb20c45fcbf8
data/colorls.gemspec CHANGED
@@ -36,7 +36,6 @@ Gem::Specification.new do |spec|
36
36
  spec.post_install_message = ColorLS::POST_INSTALL_MESSAGE
37
37
 
38
38
  spec.add_runtime_dependency 'filesize'
39
- spec.add_runtime_dependency 'git'
40
39
  spec.add_runtime_dependency 'rainbow'
41
40
  spec.add_runtime_dependency 'rake'
42
41
 
data/lib/colorls.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'yaml'
2
2
  require 'etc'
3
3
  require 'filesize'
4
- require 'git'
5
4
  require 'rainbow/ext/string'
6
5
 
7
6
  require 'colorls/core'
8
7
  require 'colorls/flags'
9
8
  require 'colorls/load_from_yaml'
10
9
  require 'colorls/monkeys'
10
+ require 'colorls/git'
data/lib/colorls/core.rb CHANGED
@@ -2,7 +2,7 @@ module ColorLS
2
2
  class Core
3
3
  def initialize(input=nil, all: false, report: false, sort: false, show: false,
4
4
  one_per_line: false, git_status: false,long: false, almost_all: false, tree: false, colors: [])
5
- @input = input || Dir.pwd
5
+ @input = init_input_path(input)
6
6
  @count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
7
7
  @all = all
8
8
  @almost_all = almost_all
@@ -12,7 +12,7 @@ module ColorLS
12
12
  @one_per_line = one_per_line
13
13
  @long = long
14
14
  @tree = tree
15
- @git_status = git_status
15
+ process_git_status_details(git_status)
16
16
  @screen_width = `tput cols`.chomp.to_i
17
17
  @colors = colors
18
18
 
@@ -39,6 +39,17 @@ module ColorLS
39
39
 
40
40
  private
41
41
 
42
+ def init_input_path(input)
43
+ return Dir.pwd unless input
44
+ return input unless Dir.exist?(input)
45
+
46
+ actual = Dir.pwd
47
+ Dir.chdir(input)
48
+ input = Dir.pwd
49
+ Dir.chdir(actual)
50
+ input
51
+ end
52
+
42
53
  def init_contents(path)
43
54
  is_directory = Dir.exist?(path)
44
55
  @contents = if is_directory
@@ -216,25 +227,49 @@ module ColorLS
216
227
  mtime.colorize(@colors[:no_modifier])
217
228
  end
218
229
 
219
- def git_info(path, content)
220
- return '' unless @git_status
230
+ def process_git_status_details(git_status)
231
+ return false unless git_status
232
+
233
+ actual_path = Dir.pwd
234
+ Dir.chdir(@input)
221
235
  until File.exist?('.git') # check whether the repository is git controlled
222
- return '' if Dir.pwd=='/'
236
+ return false if Dir.pwd=='/'
223
237
  Dir.chdir('..')
224
238
  end
225
239
 
226
- relative_path = path.remove(Dir.pwd+'/')
240
+ @git_root_path = Dir.pwd
241
+ Dir.chdir(actual_path)
242
+
243
+ @git_status = Git.status(@git_root_path)
244
+ end
245
+
246
+ def git_info(path, content)
247
+ return '' unless @git_status
248
+
249
+ # puts "\n\n"
250
+
251
+ Dir.chdir(@git_root_path)
252
+ relative_path = path.remove(@git_root_path+'/')
227
253
  relative_path = relative_path==path ? '' : relative_path+'/'
254
+ content_path = "#{relative_path}#{content}"
255
+ content_type = Dir.exist?("#{@git_root_path}/#{content_path}") ? :dir : :file
228
256
 
229
- status = Git.open('.').status
230
- git_info_of_file("#{relative_path}#{content}", status)
257
+ if content_type == :file then git_file_info(content_path)
258
+ else git_dir_info(content_path)
259
+ end
260
+ # puts "\n\n"
261
+ end
262
+
263
+ def git_file_info(path)
264
+ return ' ✓ '.colorize(@colors[:unchanged]) unless @git_status[path]
265
+ Git.colored_status_symbols(@git_status[path], @colors)
231
266
  end
232
267
 
233
- def git_info_of_file(path, status)
234
- return '(A)'.colorize(@colors[:added]) if status.added.keys.any? { |a| a.include?(path) }
235
- return '(?)'.colorize(@colors[:untracked]) if status.untracked.keys.any? { |u| u.include?(path) }
236
- return '(C)'.colorize(@colors[:changed]) if status.changed.keys.any? { |c| c.include?(path) }
237
- ' '.colorize(@colors[:unchanged])
268
+ def git_dir_info(path)
269
+ modes = @git_status.select { |file, _mode| file.start_with?(path) }.values
270
+
271
+ return ''.colorize(@colors[:unchanged]) if modes.empty?
272
+ Git.colored_status_symbols(modes.join.uniq, @colors)
238
273
  end
239
274
 
240
275
  def long_info(path, content)
@@ -0,0 +1,33 @@
1
+ module ColorLS
2
+ class Git < Core
3
+ def self.status(repo_path)
4
+ actual = Dir.pwd
5
+ Dir.chdir(repo_path)
6
+
7
+ @git_status = {}
8
+
9
+ `git status --short`.split("\n").map { |x| x.split(' ') }.each do |mode, file|
10
+ @git_status[file] = mode
11
+ end
12
+
13
+ Dir.chdir(actual)
14
+ @git_status
15
+ end
16
+
17
+ def self.colored_status_symbols(modes, colors)
18
+ modes =
19
+ case modes.length
20
+ when 1 then " #{modes} "
21
+ when 2 then " #{modes} "
22
+ when 3 then "#{modes} "
23
+ when 4 then modes
24
+ end
25
+
26
+ modes
27
+ .gsub('?', '?'.colorize(colors[:untracked]))
28
+ .gsub('A', 'A'.colorize(colors[:addition]))
29
+ .gsub('M', 'M'.colorize(colors[:modification]))
30
+ .gsub('D', 'D'.colorize(colors[:deletion]))
31
+ end
32
+ end
33
+ end
@@ -4,22 +4,26 @@ class String
4
4
  end
5
5
 
6
6
  def remove(pattern)
7
- self.gsub(pattern, '')
7
+ gsub(pattern, '')
8
+ end
9
+
10
+ def uniq
11
+ split('').uniq.join
8
12
  end
9
13
  end
10
14
 
11
15
  class Hash
12
16
  def symbolize_keys
13
- keys.each do |key|
14
- new_key = (key.to_sym rescue key.to_s.to_sym)
15
- self[new_key] = delete(key)
17
+ new_hash = {}
18
+ each_key do |key|
19
+ new_hash[key.to_sym] = delete(key)
16
20
  end
17
- self
21
+ new_hash
18
22
  end
19
23
  end
20
24
 
21
25
  class Array
22
26
  def sum
23
- self.inject(:+)
27
+ inject(:+)
24
28
  end
25
- end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module ColorLS
2
- VERSION = '1.0.8'.freeze
2
+ VERSION = '1.0.9'.freeze
3
3
  end
@@ -32,7 +32,8 @@ error: red
32
32
  normal: darkkhaki
33
33
 
34
34
  # Git
35
- unchanged: forestgreen
36
- added: chartreuse
37
- changed: darkorange
38
- untracked: darkred
35
+ addition: chartreuse
36
+ modification: darkkhaki
37
+ deletion: darkred
38
+ untracked: darkorange
39
+ unchanged: forestgreen
@@ -32,7 +32,8 @@ error: red
32
32
  normal: black
33
33
 
34
34
  # Git
35
- unchanged: darkgreen
36
- added: saddlebrown
37
- changed: saddlebrown
38
- untracked: darkred
35
+ addition: chartreuse
36
+ modification: darkkhaki
37
+ deletion: darkred
38
+ untracked: darkorange
39
+ unchanged: darkgreen
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colorls
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Athitya Kumar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-28 00:00:00.000000000 Z
11
+ date: 2017-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filesize
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: git
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rainbow
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -176,6 +162,7 @@ files:
176
162
  - lib/colorls.rb
177
163
  - lib/colorls/core.rb
178
164
  - lib/colorls/flags.rb
165
+ - lib/colorls/git.rb
179
166
  - lib/colorls/load_from_yaml.rb
180
167
  - lib/colorls/monkeys.rb
181
168
  - lib/colorls/version.rb