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 +4 -4
- data/colorls.gemspec +0 -1
- data/lib/colorls.rb +1 -1
- data/lib/colorls/core.rb +48 -13
- data/lib/colorls/git.rb +33 -0
- data/lib/colorls/monkeys.rb +11 -7
- data/lib/colorls/version.rb +1 -1
- data/lib/yaml/dark_colors.yaml +5 -4
- data/lib/yaml/light_colors.yaml +5 -4
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4071319ab261196949f1a3cf87ebe1c55d7582c
|
4
|
+
data.tar.gz: 40c07660304acb180e356b0bfaa4e7ecb6bbe2fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcacb48be3c568c7cc64815de3847c7b093950f4d834de0b55e9c969aaf791fa0d6fb7547bf347f7211872f5b9c14f035ae7044c64496d0a55c02a85c327cbed
|
7
|
+
data.tar.gz: edca7e18cef76348a81313431016de823b83b3f79d3579890db0bd0329605f53ee0c7e2c97a46fdfb9b9873e2a5c674801c5d03eba8e6dda2302bb20c45fcbf8
|
data/colorls.gemspec
CHANGED
data/lib/colorls.rb
CHANGED
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
|
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
|
-
|
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
|
220
|
-
return
|
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
|
236
|
+
return false if Dir.pwd=='/'
|
223
237
|
Dir.chdir('..')
|
224
238
|
end
|
225
239
|
|
226
|
-
|
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
|
-
|
230
|
-
|
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
|
234
|
-
|
235
|
-
|
236
|
-
return '
|
237
|
-
|
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)
|
data/lib/colorls/git.rb
ADDED
@@ -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
|
data/lib/colorls/monkeys.rb
CHANGED
@@ -4,22 +4,26 @@ class String
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def remove(pattern)
|
7
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
17
|
+
new_hash = {}
|
18
|
+
each_key do |key|
|
19
|
+
new_hash[key.to_sym] = delete(key)
|
16
20
|
end
|
17
|
-
|
21
|
+
new_hash
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
25
|
class Array
|
22
26
|
def sum
|
23
|
-
|
27
|
+
inject(:+)
|
24
28
|
end
|
25
|
-
end
|
29
|
+
end
|
data/lib/colorls/version.rb
CHANGED
data/lib/yaml/dark_colors.yaml
CHANGED
@@ -32,7 +32,8 @@ error: red
|
|
32
32
|
normal: darkkhaki
|
33
33
|
|
34
34
|
# Git
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
untracked:
|
35
|
+
addition: chartreuse
|
36
|
+
modification: darkkhaki
|
37
|
+
deletion: darkred
|
38
|
+
untracked: darkorange
|
39
|
+
unchanged: forestgreen
|
data/lib/yaml/light_colors.yaml
CHANGED
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.
|
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-
|
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
|