colorls 1.0.9 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -1
- data/.travis.yml +6 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +101 -27
- data/Rakefile +35 -1
- data/colorls.gemspec +15 -1
- data/exe/colorls +1 -0
- data/lib/colorls.rb +5 -1
- data/lib/colorls/core.rb +127 -143
- data/lib/colorls/fileinfo.rb +69 -0
- data/lib/colorls/flags.rb +60 -22
- data/lib/colorls/git.rb +6 -6
- data/lib/colorls/version.rb +1 -1
- data/lib/colorls/yaml.rb +23 -0
- data/lib/tab_complete.sh +9 -4
- data/man/colorls.1 +135 -0
- data/man/colorls.1.ronn +41 -0
- data/zsh/_colorls +38 -0
- metadata +85 -15
- data/lib/colorls/load_from_yaml.rb +0 -22
- data/readme/pending.png +0 -0
- data/readme/usage1.png +0 -0
- data/readme/usage2.png +0 -0
- data/readme/usage3.png +0 -0
- data/readme/usage4.png +0 -0
- data/readme/usage5.png +0 -0
- data/readme/usage6.png +0 -0
- data/readme/usage7.png +0 -0
- data/readme/usage8.png +0 -0
- data/readme/usage9.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: baadf69e664b9bab7c78f96af16d833f7d03302c
|
4
|
+
data.tar.gz: e72d0b65aefd804aec27dab9865fb9066e9c56d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5234ec2b037d9b50f82eac2cfdec97b0befc6f25f563fecd55a25b0f312b6b54acfe9ff573c73a636e6902b2e08dfba8cdff8d89e41182733d9d700a1b07ba10
|
7
|
+
data.tar.gz: b6d1d437c80186e03850a8c184892b78cf98ecd261ac41820033a294e3899a671eb0b0d96f4fccdfa6322149653945cd3f9f64ee65611353e80ad9f9e4983eb9
|
data/.rubocop.yml
CHANGED
@@ -11,6 +11,7 @@ AllCops:
|
|
11
11
|
TargetRubyVersion: 2.1
|
12
12
|
|
13
13
|
# Preferred codebase style ---------------------------------------------
|
14
|
+
|
14
15
|
Layout/ExtraSpacing:
|
15
16
|
AllowForAlignment: true
|
16
17
|
|
@@ -46,7 +47,7 @@ Metrics/ModuleLength:
|
|
46
47
|
Max: 200
|
47
48
|
|
48
49
|
Metrics/ClassLength:
|
49
|
-
Max:
|
50
|
+
Max: 350
|
50
51
|
|
51
52
|
Metrics/ParameterLists:
|
52
53
|
Max: 15
|
data/.travis.yml
CHANGED
@@ -6,6 +6,7 @@ rvm:
|
|
6
6
|
- '2.2'
|
7
7
|
- '2.3.0'
|
8
8
|
- '2.4.0'
|
9
|
+
- '2.5.0'
|
9
10
|
|
10
11
|
script:
|
11
12
|
- bundle exec rubocop
|
@@ -25,6 +26,11 @@ script:
|
|
25
26
|
- colorls --sd
|
26
27
|
- colorls --sf
|
27
28
|
- colorls -t
|
29
|
+
- colorls --sort=time
|
30
|
+
- colorls -U
|
31
|
+
- colorls --sort=none
|
32
|
+
- colorls -S
|
33
|
+
- colorls --sort=size
|
28
34
|
- colorls -h
|
29
35
|
- colorls --gs
|
30
36
|
- colorls spec/fixtures/symlinks
|
data/CONTRIBUTING.md
CHANGED
@@ -7,7 +7,7 @@ Before sending a Pull Request, please make sure that you're assigned the task on
|
|
7
7
|
- If a relevant issue already exists, discuss on the issue and get it assigned to yourself on GitHub.
|
8
8
|
- If no relevant issue exists, open a new issue and get it assigned to yourself on GitHub.
|
9
9
|
|
10
|
-
Please proceed with a Pull Request only after you're assigned. It'd be sad if your Pull Request (and your hardwork) isn't accepted just because it isn't
|
10
|
+
Please proceed with a Pull Request only after you're assigned. It'd be sad if your Pull Request (and your hardwork) isn't accepted just because it isn't ideologically compatible.
|
11
11
|
|
12
12
|
# Developing the gem
|
13
13
|
|
data/README.md
CHANGED
@@ -6,16 +6,31 @@
|
|
6
6
|
[](https://badge.fury.io/rb/colorls)
|
7
7
|
[](https://travis-ci.org/athityakumar/colorls)
|
8
8
|
[](http://makeapullrequest.com)
|
9
|
+
[](https://waffle.io/athityakumar/colorls?utm_source=badge)
|
9
10
|
|
10
11
|
A Ruby script that colorizes the `ls` output with color and icons. Here are the screenshots of working example on an iTerm2 terminal (Mac OS), `oh-my-zsh` with `powerlevel9k` theme and `powerline nerd-font + awesome-config` font with the `Solarized Dark` color theme.
|
11
12
|
|
12
|
-

|
13
14
|
|
14
15
|
*If you're interested in knowing the powerlevel9k configuration to get this prompt, have a look at [this gist](https://gist.github.com/athityakumar/1bd5e9e24cd2a1891565573a893993eb).*
|
15
16
|
|
16
17
|
# Table of contents
|
17
18
|
|
18
19
|
- [Usage](#usage)
|
20
|
+
- [Flags](#flags)
|
21
|
+
- `-1`
|
22
|
+
- `-a` (or) `--all`
|
23
|
+
- `-A` (or) `--almost-all`
|
24
|
+
- `-d` (or) `--dirs`
|
25
|
+
- `-f` (or) `--files`
|
26
|
+
- `-h` (or) `--help`
|
27
|
+
- `-l` (or) `--long`
|
28
|
+
- `-r` (or) `--report`
|
29
|
+
- `-t` (or) `--tree`
|
30
|
+
- `--gs` (or) `--git-status`
|
31
|
+
- `--sd` (or) `--sort-dirs` or `--group-directories-first`
|
32
|
+
- `--sf` (or) `--sort-files`
|
33
|
+
- [Combination of flags](#combination-of-flags)
|
19
34
|
- [Installation](#installation)
|
20
35
|
- [Recommended configurations](#recommended-configurations)
|
21
36
|
- [Custom configurations](#custom-configurations)
|
@@ -28,34 +43,73 @@ A Ruby script that colorizes the `ls` output with color and icons. Here are the
|
|
28
43
|
|
29
44
|
[(Back to top)](#table-of-contents)
|
30
45
|
|
31
|
-
|
46
|
+
Man pages have been added. Checkout `man colorls`.
|
32
47
|
|
33
|
-
|
48
|
+
### Flags
|
34
49
|
|
35
|
-
- With
|
50
|
+
- With `-1` : Lists one entry per line
|
36
51
|
|
37
|
-

|
38
53
|
|
39
|
-
- With
|
54
|
+
- With `-a` (or) `--all` : Does not ignore entries starting with '.'
|
40
55
|
|
41
|
-

|
56
|
+

|
43
57
|
|
44
|
-
- With
|
58
|
+
- With `-A` (or) `--almost-all` : Does not ignore entries starting with '.', except `./` and `../`
|
45
59
|
|
46
|
-

|
60
|
+

|
48
61
|
|
49
|
-
- With
|
62
|
+
- With `-d` (or) `--dirs` : Shows only directories
|
50
63
|
|
51
|
-

|
64
|
+

|
53
65
|
|
54
|
-
- With `-
|
66
|
+
- With `-f` (or) `--files` : Shows only files
|
55
67
|
|
56
|
-

|
57
69
|
|
58
|
-
-
|
70
|
+
- With `-h` (or) `--help` : Prints a very helpful help menu
|
71
|
+
|
72
|
+

|
73
|
+
|
74
|
+
- With `-l` (or) `--long` : Shows in long listing format
|
75
|
+
|
76
|
+

|
77
|
+
|
78
|
+
- With `-r` (or) `--report` : Shows brief report about number of files and folders shown
|
79
|
+
|
80
|
+

|
81
|
+
|
82
|
+
- With `-t` (or) `--tree` : Shows tree view of the directory
|
83
|
+
|
84
|
+

|
85
|
+
|
86
|
+
- With `--gs` (or) `--git-status` : Shows git status for each entry
|
87
|
+
|
88
|
+

|
89
|
+
|
90
|
+
- With `--sd` (or) `--sort-dirs` or `--group-directories-first` : Shows directories first, followed by files
|
91
|
+
|
92
|
+

|
93
|
+
|
94
|
+
- With `--sf` (or) `--sort-files` : Shows files first, followed by directories
|
95
|
+
|
96
|
+

|
97
|
+
|
98
|
+
- 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
|
+
|
100
|
+
### Combination of flags
|
101
|
+
|
102
|
+
- Using `--gs` with `-t` :
|
103
|
+
|
104
|
+

|
105
|
+
|
106
|
+
- Using `--gs` with `-l` :
|
107
|
+
|
108
|
+

|
109
|
+
|
110
|
+
- Using `--sd` with `-l` and `-A` :
|
111
|
+
|
112
|
+

|
59
113
|
|
60
114
|
# Installation
|
61
115
|
|
@@ -82,16 +136,17 @@ A Ruby script that colorizes the `ls` output with color and icons. Here are the
|
|
82
136
|
|
83
137
|
5. Start using `colorls` :tada:
|
84
138
|
|
85
|
-
6. Have a look at [Recommended configurations](#recommended-configurations).
|
139
|
+
6. Have a look at [Recommended configurations](#recommended-configurations) and [Custom configurations](#custom-configurations).
|
86
140
|
|
87
141
|
# Recommended configurations
|
88
142
|
|
89
143
|
[(Back to top)](#table-of-contents)
|
90
144
|
|
91
|
-
1. To add some short command (say, `lc`) with some flag options (say, `-
|
145
|
+
1. To add some short command (say, `lc`) with some flag options (say, `-l`, `-A`, `--sd`) by default, add this to your shell configuration file (`~/.bashrc`, `~/.zshrc`, etc.) :
|
92
146
|
```sh
|
93
|
-
alias lc='colorls -
|
147
|
+
alias lc='colorls -lA --sd'
|
94
148
|
```
|
149
|
+
|
95
150
|
2. For changing the icon(s) to other unicode icons of choice (select icons from [here](https://nerdfonts.com/)), change the YAML files in a text editor of your choice (say, `subl`)
|
96
151
|
|
97
152
|
```sh
|
@@ -102,17 +157,36 @@ A Ruby script that colorizes the `ls` output with color and icons. Here are the
|
|
102
157
|
|
103
158
|
[(Back to top)](#table-of-contents)
|
104
159
|
|
105
|
-
You can overwrite the existing icons and colors mapping by
|
160
|
+
You can overwrite the existing icons and colors mapping by copying the yaml files from `$(dirname $(gem which colorls))/yaml` into `~/.config/colorls`, and changing them.
|
106
161
|
|
107
|
-
|
162
|
+
- To overwrite color mapping :
|
108
163
|
|
109
|
-
Let's say you
|
164
|
+
Please have a look at the [list of supported color names](https://github.com/sickill/rainbow#color-list). Let's say that you're using the dark color scheme and would like to change the color of untracked file (`??`) in the `--git-status` flag to yellow. Copy the defaut `dark_colors.yaml` and change it.
|
165
|
+
|
166
|
+
```sh
|
167
|
+
cp $(dirname $(gem which colorls))/yaml/dark_colors.yaml ~/.config/colorls/dark_colors.yaml`
|
168
|
+
```
|
169
|
+
|
170
|
+
In the `~/.config/colorls/dark_colors.yaml` file, change the color set for `untracked` from `darkorange` to `yellow`, and save the change.
|
171
|
+
|
172
|
+
```
|
173
|
+
untracked: yellow
|
174
|
+
```
|
175
|
+
|
176
|
+
- To overwrite icon mapping :
|
177
|
+
|
178
|
+
Please have a look at the [list of supported icons](https://nerdfonts.com/). Let's say you want to add an icon for swift files. Copy the default `files.yaml` and change it.
|
179
|
+
|
180
|
+
```sh
|
181
|
+
cp $(dirname $(gem which colorls))/yaml/files.yaml ~/.config/colorls/files.yaml`
|
182
|
+
```
|
183
|
+
|
184
|
+
In the `~/.config/colorls/files.yaml` file, add a new icon / change an existing icon, and save the change.
|
110
185
|
|
111
|
-
```
|
112
|
-
swift: "\uF179"
|
113
|
-
```
|
114
186
|
|
115
|
-
|
187
|
+
```
|
188
|
+
swift: "\uF179"
|
189
|
+
```
|
116
190
|
|
117
191
|
# Updating
|
118
192
|
|
data/Rakefile
CHANGED
@@ -6,6 +6,40 @@ require 'rspec/core/rake_task'
|
|
6
6
|
RSpec::Core::RakeTask.new
|
7
7
|
|
8
8
|
require 'rubocop/rake_task'
|
9
|
-
RuboCop::RakeTask.new
|
9
|
+
RuboCop::RakeTask.new do |task|
|
10
|
+
task.requires << 'rubocop-rspec'
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Build the manual'
|
14
|
+
file 'man/colorls.1' => ['man/colorls.1.ronn', 'lib/colorls/flags.rb'] do
|
15
|
+
require 'colorls'
|
16
|
+
require 'ronn'
|
17
|
+
|
18
|
+
flags = ColorLS::Flags.new
|
19
|
+
attributes = {
|
20
|
+
date: Date.iso8601(`git log -1 --pretty=format:%aI -- man/colorls.1`),
|
21
|
+
manual: 'colorls Manual',
|
22
|
+
organization: "colorls #{ColorLS::VERSION}"
|
23
|
+
}
|
24
|
+
doc = Ronn::Document.new(nil, attributes) do
|
25
|
+
template = IO.read('man/colorls.1.ronn')
|
26
|
+
|
27
|
+
section = ''
|
28
|
+
flags.options.each do |o|
|
29
|
+
section += <<OPTION
|
30
|
+
* `#{o.flags.join('`, `')}`:
|
31
|
+
#{o.desc.join("<br>\n")}
|
32
|
+
|
33
|
+
OPTION
|
34
|
+
end
|
35
|
+
template.sub('{{ OPTIONS }}', section)
|
36
|
+
end
|
37
|
+
IO.write('man/colorls.1', doc.convert('roff'))
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Build the Zsh completion file'
|
41
|
+
file 'zsh/_colorls' => ['lib/colorls/flags.rb'] do
|
42
|
+
ruby "exe/colorls '--*-completion-zsh=colorls' > zsh/_colorls"
|
43
|
+
end
|
10
44
|
|
11
45
|
task default: %w[spec rubocop]
|
data/colorls.gemspec
CHANGED
@@ -14,9 +14,16 @@ ColorLS::POST_INSTALL_MESSAGE = %(
|
|
14
14
|
Help menu : `colorls -h` provides all possible flag options
|
15
15
|
|
16
16
|
Tab completion enabled for flags
|
17
|
+
|
18
|
+
-t flag : Previously short for --tree, has been re-allocated to sort results by time
|
19
|
+
-r flag : Previously short for --report, has been re-allocated to reverse sort results
|
20
|
+
|
21
|
+
Man pages have been added. Checkout `man colorls`.
|
22
|
+
|
17
23
|
*******************************************************************
|
18
24
|
).freeze
|
19
25
|
|
26
|
+
# rubocop:disable Metrics/BlockLength
|
20
27
|
Gem::Specification.new do |spec|
|
21
28
|
spec.name = 'colorls'
|
22
29
|
spec.version = ColorLS::VERSION
|
@@ -29,20 +36,27 @@ Gem::Specification.new do |spec|
|
|
29
36
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
30
37
|
f.match(%r{^(test|spec|features)/})
|
31
38
|
end
|
39
|
+
|
32
40
|
spec.bindir = 'exe'
|
33
41
|
spec.executables = 'colorls'
|
34
42
|
spec.require_paths = ['lib']
|
35
43
|
|
36
44
|
spec.post_install_message = ColorLS::POST_INSTALL_MESSAGE
|
37
45
|
|
46
|
+
spec.add_runtime_dependency 'clocale'
|
38
47
|
spec.add_runtime_dependency 'filesize'
|
48
|
+
spec.add_runtime_dependency 'manpages'
|
39
49
|
spec.add_runtime_dependency 'rainbow'
|
40
|
-
spec.add_runtime_dependency 'rake'
|
41
50
|
|
42
51
|
spec.add_development_dependency 'bundler', '~> 1.15'
|
43
52
|
spec.add_development_dependency 'diffy'
|
53
|
+
spec.add_development_dependency 'rake'
|
54
|
+
spec.add_development_dependency 'ronn'
|
44
55
|
spec.add_development_dependency 'rspec'
|
45
56
|
spec.add_development_dependency 'rspec-its'
|
46
57
|
spec.add_development_dependency 'rubocop'
|
58
|
+
spec.add_development_dependency 'rubocop-rspec'
|
47
59
|
spec.add_development_dependency 'rubygems-tasks'
|
60
|
+
spec.add_development_dependency 'simplecov'
|
48
61
|
end
|
62
|
+
# rubocop:enable Metrics/BlockLength
|
data/exe/colorls
CHANGED
data/lib/colorls.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'etc'
|
3
|
+
require 'English'
|
3
4
|
require 'filesize'
|
5
|
+
require 'io/console'
|
4
6
|
require 'rainbow/ext/string'
|
7
|
+
require 'clocale'
|
5
8
|
|
6
9
|
require 'colorls/core'
|
10
|
+
require 'colorls/fileinfo'
|
7
11
|
require 'colorls/flags'
|
8
|
-
require 'colorls/
|
12
|
+
require 'colorls/yaml'
|
9
13
|
require 'colorls/monkeys'
|
10
14
|
require 'colorls/git'
|
data/lib/colorls/core.rb
CHANGED
@@ -1,23 +1,29 @@
|
|
1
1
|
module ColorLS
|
2
2
|
class Core
|
3
|
-
def initialize(input
|
4
|
-
|
5
|
-
|
3
|
+
def initialize(input, all: false, report: false, sort: false, show: false,
|
4
|
+
mode: nil, git_status: false, almost_all: false, colors: [], group: nil,
|
5
|
+
reverse: false)
|
6
|
+
@input = File.absolute_path(input)
|
6
7
|
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
|
7
8
|
@all = all
|
8
9
|
@almost_all = almost_all
|
9
10
|
@report = report
|
10
11
|
@sort = sort
|
12
|
+
@reverse = reverse
|
13
|
+
@group = group
|
11
14
|
@show = show
|
12
|
-
@one_per_line = one_per_line
|
13
|
-
@long = long
|
14
|
-
@tree = tree
|
15
|
+
@one_per_line = mode == :one_per_line
|
16
|
+
@long = mode == :long
|
17
|
+
@tree = mode == :tree
|
15
18
|
process_git_status_details(git_status)
|
16
|
-
|
19
|
+
|
20
|
+
@screen_width = IO.console.winsize[1]
|
21
|
+
@screen_width = 80 if @screen_width.zero?
|
22
|
+
|
17
23
|
@colors = colors
|
18
24
|
|
19
|
-
@contents = init_contents(
|
20
|
-
@max_widths = @contents.map
|
25
|
+
@contents = init_contents(input)
|
26
|
+
@max_widths = @contents.map { |c| c.name.length }
|
21
27
|
init_icons
|
22
28
|
end
|
23
29
|
|
@@ -29,45 +35,35 @@ module ColorLS
|
|
29
35
|
tree_traverse(@input, 0, 2)
|
30
36
|
else
|
31
37
|
@contents = chunkify
|
32
|
-
@max_widths = @contents.transpose.map { |c| c.map(&:length).max }
|
33
38
|
@contents.each { |chunk| ls_line(chunk) }
|
34
39
|
end
|
35
|
-
print "\n"
|
36
40
|
display_report if @report
|
37
41
|
true
|
38
42
|
end
|
39
43
|
|
40
44
|
private
|
41
45
|
|
42
|
-
def
|
43
|
-
|
44
|
-
return input unless Dir.exist?(input)
|
46
|
+
def init_contents(path)
|
47
|
+
info = FileInfo.new(path, link_info = @long)
|
45
48
|
|
46
|
-
|
47
|
-
|
48
|
-
input = Dir.pwd
|
49
|
-
Dir.chdir(actual)
|
50
|
-
input
|
51
|
-
end
|
49
|
+
if info.directory?
|
50
|
+
@contents = Dir.entries(path)
|
52
51
|
|
53
|
-
|
54
|
-
is_directory = Dir.exist?(path)
|
55
|
-
@contents = if is_directory
|
56
|
-
Dir.entries(path)
|
57
|
-
else
|
58
|
-
@input = File.dirname(path)
|
59
|
-
[File.basename(path)]
|
60
|
-
end
|
52
|
+
filter_hidden_contents
|
61
53
|
|
62
|
-
|
63
|
-
filter_contents(path) if @show
|
64
|
-
sort_contents(path) if @sort
|
54
|
+
@contents.map! { |e| FileInfo.new(File.join(path, e), link_info = @long) }
|
65
55
|
|
56
|
+
filter_contents if @show
|
57
|
+
sort_contents if @sort
|
58
|
+
group_contents if @group
|
59
|
+
else
|
60
|
+
@contents = [info]
|
61
|
+
end
|
66
62
|
@total_content_length = @contents.length
|
67
63
|
|
68
64
|
return @contents unless @long
|
69
|
-
init_user_lengths
|
70
|
-
init_group_lengths
|
65
|
+
init_user_lengths
|
66
|
+
init_group_lengths
|
71
67
|
@contents
|
72
68
|
end
|
73
69
|
|
@@ -76,61 +72,52 @@ module ColorLS
|
|
76
72
|
@contents.keep_if { |x| !x.start_with? '.' } unless @all || @almost_all
|
77
73
|
end
|
78
74
|
|
79
|
-
def init_user_lengths
|
75
|
+
def init_user_lengths
|
80
76
|
@userlength = @contents.map do |c|
|
81
|
-
|
82
|
-
begin
|
83
|
-
user = Etc.getpwuid(File.stat("#{path}/#{c}").uid).name
|
84
|
-
rescue ArgumentError
|
85
|
-
user = File.stat("#{path}/#{c}").uid
|
86
|
-
end
|
87
|
-
user.to_s.length
|
77
|
+
c.owner.length
|
88
78
|
end.max
|
89
79
|
end
|
90
80
|
|
91
|
-
def init_group_lengths
|
81
|
+
def init_group_lengths
|
92
82
|
@grouplength = @contents.map do |c|
|
93
|
-
|
94
|
-
begin
|
95
|
-
group = Etc.getgrgid(File.stat("#{path}/#{c}").gid).name
|
96
|
-
rescue ArgumentError
|
97
|
-
group = File.stat("#{path}/#{c}").gid
|
98
|
-
end
|
99
|
-
group.to_s.length
|
83
|
+
c.group.length
|
100
84
|
end.max
|
101
85
|
end
|
102
86
|
|
103
|
-
def filter_contents
|
87
|
+
def filter_contents
|
104
88
|
@contents.keep_if do |x|
|
105
|
-
|
106
|
-
!Dir.exist?("#{path}/#{x}")
|
89
|
+
x.directory? == (@show == :dirs)
|
107
90
|
end
|
108
91
|
end
|
109
92
|
|
110
|
-
def sort_contents
|
111
|
-
@
|
93
|
+
def sort_contents
|
94
|
+
case @sort
|
95
|
+
when :time
|
96
|
+
@contents.sort_by! { |a| -a.mtime.to_f }
|
97
|
+
when :size
|
98
|
+
@contents.sort_by! { |a| -a.size }
|
99
|
+
else
|
100
|
+
@contents.sort_by! { |a| CLocale.strxfrm(a.name) }
|
101
|
+
end
|
102
|
+
@contents.reverse! if @reverse
|
112
103
|
end
|
113
104
|
|
114
|
-
def
|
115
|
-
|
116
|
-
is_b_dir = Dir.exist?("#{path}/#{b}")
|
117
|
-
|
118
|
-
return cmp_by_alpha(a, b) unless is_a_dir ^ is_b_dir
|
105
|
+
def group_contents
|
106
|
+
return unless @group
|
119
107
|
|
120
|
-
|
121
|
-
result *= -1 if @sort == :files
|
122
|
-
result
|
123
|
-
end
|
108
|
+
dirs, files = @contents.partition(&:directory?)
|
124
109
|
|
125
|
-
|
126
|
-
|
110
|
+
@contents = case @group
|
111
|
+
when :dirs then dirs.push(*files)
|
112
|
+
when :files then files.push(*dirs)
|
113
|
+
end
|
127
114
|
end
|
128
115
|
|
129
116
|
def init_icons
|
130
|
-
@files = ColorLS.
|
131
|
-
@file_aliases = ColorLS.
|
132
|
-
@folders = ColorLS.
|
133
|
-
@folder_aliases = ColorLS.
|
117
|
+
@files = ColorLS::Yaml.new('files.yaml').load
|
118
|
+
@file_aliases = ColorLS::Yaml.new('file_aliases.yaml').load(aliase: true)
|
119
|
+
@folders = ColorLS::Yaml.new('folders.yaml').load
|
120
|
+
@folder_aliases = ColorLS::Yaml.new('folder_aliases.yaml').load(aliase: true)
|
134
121
|
|
135
122
|
@file_keys = @files.keys
|
136
123
|
@file_aliase_keys = @file_aliases.keys
|
@@ -144,25 +131,25 @@ module ColorLS
|
|
144
131
|
def chunkify
|
145
132
|
return @contents.zip if @one_per_line || @long
|
146
133
|
|
147
|
-
chunk_size = @contents.
|
134
|
+
chunk_size = @contents.size
|
135
|
+
max_widths = @max_widths
|
148
136
|
|
149
|
-
until in_line(chunk_size) || chunk_size <= 1
|
137
|
+
until in_line(chunk_size, max_widths) || chunk_size <= 1
|
150
138
|
chunk_size -= 1
|
151
|
-
|
139
|
+
max_widths = @max_widths.each_slice(chunk_size).to_a
|
140
|
+
max_widths[-1] += [0] * (chunk_size - max_widths.last.size)
|
141
|
+
max_widths = max_widths.transpose.map(&:max)
|
152
142
|
end
|
153
|
-
|
154
|
-
|
143
|
+
@max_widths = max_widths
|
144
|
+
@contents = get_chunk(chunk_size)
|
155
145
|
end
|
156
146
|
|
157
147
|
def get_chunk(chunk_size)
|
158
|
-
|
159
|
-
chunk[-1] += [''] * (chunk_size - chunk.last.count)
|
160
|
-
@max_widths = chunk.transpose.map { |c| c.map(&:length).max }
|
161
|
-
chunk
|
148
|
+
@contents.each_slice(chunk_size).to_a
|
162
149
|
end
|
163
150
|
|
164
|
-
def in_line(chunk_size)
|
165
|
-
(
|
151
|
+
def in_line(chunk_size, max_widths)
|
152
|
+
(max_widths.sum + 12 * chunk_size <= @screen_width)
|
166
153
|
end
|
167
154
|
|
168
155
|
def display_report
|
@@ -193,54 +180,39 @@ module ColorLS
|
|
193
180
|
mode
|
194
181
|
end
|
195
182
|
|
196
|
-
def user_info(
|
197
|
-
|
198
|
-
|
199
|
-
rescue ArgumentError
|
200
|
-
user = stat.uid
|
201
|
-
end
|
202
|
-
user = user.to_s.ljust(@userlength, ' ')
|
203
|
-
user.colorize(@colors[:user]) if user == Etc.getlogin
|
183
|
+
def user_info(content)
|
184
|
+
user = content.owner.ljust(@userlength, ' ')
|
185
|
+
user.colorize(@colors[:user]) if content.owned?
|
204
186
|
end
|
205
187
|
|
206
|
-
def group_info(
|
207
|
-
begin
|
208
|
-
group = Etc.getgrgid(stat.gid).name
|
209
|
-
rescue ArgumentError
|
210
|
-
group = stat.gid
|
211
|
-
end
|
188
|
+
def group_info(group)
|
212
189
|
group.to_s.ljust(@grouplength, ' ').colorize(@colors[:normal])
|
213
190
|
end
|
214
191
|
|
215
|
-
def size_info(
|
216
|
-
size = Filesize.from("#{
|
192
|
+
def size_info(filesize)
|
193
|
+
size = Filesize.from("#{filesize} B").pretty.split(' ')
|
217
194
|
size = "#{size[0][0..-4].rjust(3,' ')} #{size[1].ljust(3,' ')}"
|
218
|
-
return size.colorize(@colors[:file_large]) if
|
219
|
-
return size.colorize(@colors[:file_medium]) if
|
195
|
+
return size.colorize(@colors[:file_large]) if filesize >= 512 * 1024 ** 2
|
196
|
+
return size.colorize(@colors[:file_medium]) if filesize >= 128 * 1024 ** 2
|
220
197
|
size.colorize(@colors[:file_small])
|
221
198
|
end
|
222
199
|
|
223
|
-
def mtime_info(
|
224
|
-
mtime =
|
225
|
-
|
226
|
-
return mtime.colorize(@colors[:
|
200
|
+
def mtime_info(file_mtime)
|
201
|
+
mtime = file_mtime.asctime
|
202
|
+
now = Time.now
|
203
|
+
return mtime.colorize(@colors[:hour_old]) if now - file_mtime < 60 * 60
|
204
|
+
return mtime.colorize(@colors[:day_old]) if now - file_mtime < 24 * 60 * 60
|
227
205
|
mtime.colorize(@colors[:no_modifier])
|
228
206
|
end
|
229
207
|
|
230
208
|
def process_git_status_details(git_status)
|
231
209
|
return false unless git_status
|
232
210
|
|
233
|
-
|
234
|
-
Dir.chdir(@input)
|
235
|
-
until File.exist?('.git') # check whether the repository is git controlled
|
236
|
-
return false if Dir.pwd=='/'
|
237
|
-
Dir.chdir('..')
|
238
|
-
end
|
211
|
+
@git_root_path = IO.popen(['git', '-C', @input, 'rev-parse', '--show-toplevel'], err: :close, &:gets)
|
239
212
|
|
240
|
-
|
241
|
-
Dir.chdir(actual_path)
|
213
|
+
return false unless $CHILD_STATUS.success?
|
242
214
|
|
243
|
-
@git_status = Git.status(@git_root_path)
|
215
|
+
@git_status = Git.status(@git_root_path.chomp!)
|
244
216
|
end
|
245
217
|
|
246
218
|
def git_info(path, content)
|
@@ -248,14 +220,14 @@ module ColorLS
|
|
248
220
|
|
249
221
|
# puts "\n\n"
|
250
222
|
|
251
|
-
Dir.chdir(@git_root_path)
|
252
223
|
relative_path = path.remove(@git_root_path+'/')
|
253
224
|
relative_path = relative_path==path ? '' : relative_path+'/'
|
254
225
|
content_path = "#{relative_path}#{content}"
|
255
|
-
content_type = Dir.exist?("#{@git_root_path}/#{content_path}") ? :dir : :file
|
256
226
|
|
257
|
-
if
|
258
|
-
|
227
|
+
if content.directory?
|
228
|
+
git_dir_info(content_path)
|
229
|
+
else
|
230
|
+
git_file_info(content_path)
|
259
231
|
end
|
260
232
|
# puts "\n\n"
|
261
233
|
end
|
@@ -265,34 +237,46 @@ module ColorLS
|
|
265
237
|
Git.colored_status_symbols(@git_status[path], @colors)
|
266
238
|
end
|
267
239
|
|
240
|
+
Dir.class_eval do
|
241
|
+
def self.deep_entries(path)
|
242
|
+
(Dir.entries(path) - ['.', '..']).map do |entry|
|
243
|
+
if Dir.exist?("#{path}/#{entry}")
|
244
|
+
Dir.deep_entries("#{path}/#{entry}")
|
245
|
+
else
|
246
|
+
entry
|
247
|
+
end
|
248
|
+
end.flatten
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
268
252
|
def git_dir_info(path)
|
269
|
-
|
253
|
+
ignored = @git_status.select { |file, mode| file.start_with?(path) && mode=='!!' }.keys
|
254
|
+
present = Dir.deep_entries(path).map { |p| "#{path}/#{p}" }
|
255
|
+
return ' ' if (present-ignored).empty?
|
270
256
|
|
257
|
+
modes = (present-ignored).map { |file| @git_status[file] }-[nil]
|
271
258
|
return ' ✓ '.colorize(@colors[:unchanged]) if modes.empty?
|
272
259
|
Git.colored_status_symbols(modes.join.uniq, @colors)
|
273
260
|
end
|
274
261
|
|
275
|
-
def long_info(
|
262
|
+
def long_info(content)
|
276
263
|
return '' unless @long
|
277
|
-
|
278
|
-
|
279
|
-
end
|
280
|
-
stat = File.stat("#{path}/#{content}")
|
281
|
-
[mode_info(stat), user_info(stat), group_info(stat), size_info(stat), mtime_info(stat)]
|
282
|
-
.join(' ')
|
264
|
+
[mode_info(content.stats), user_info(content), group_info(content.group),
|
265
|
+
size_info(content.size), mtime_info(content.mtime)].join(' ')
|
283
266
|
end
|
284
267
|
|
285
|
-
def symlink_info(
|
286
|
-
return '' unless @long &&
|
287
|
-
|
288
|
-
|
268
|
+
def symlink_info(content)
|
269
|
+
return '' unless @long && content.symlink?
|
270
|
+
link_info = " ⇒ #{content.link_target}"
|
271
|
+
if content.dead?
|
272
|
+
"#{link_info} [Dead link]".colorize(@colors[:dead_link])
|
289
273
|
else
|
290
|
-
|
274
|
+
link_info.colorize(@colors[:link])
|
291
275
|
end
|
292
276
|
end
|
293
277
|
|
294
|
-
def slash?(
|
295
|
-
|
278
|
+
def slash?(content)
|
279
|
+
content.directory? ? '/'.colorize(@colors[:dir]) : ' '
|
296
280
|
end
|
297
281
|
|
298
282
|
def fetch_string(path, content, key, color, increment)
|
@@ -301,26 +285,26 @@ module ColorLS
|
|
301
285
|
logo = value.gsub(/\\u[\da-f]{4}/i) { |m| [m[-4..-1].to_i(16)].pack('U') }
|
302
286
|
|
303
287
|
[
|
304
|
-
long_info(
|
288
|
+
long_info(content),
|
305
289
|
" #{git_info(path,content)} ",
|
306
290
|
logo.colorize(color),
|
307
|
-
" #{content.colorize(color)}#{slash?(
|
291
|
+
" #{content.name.colorize(color)}#{slash?(content)}#{symlink_info(content)}"
|
308
292
|
].join
|
309
293
|
end
|
310
294
|
|
311
295
|
def ls_line(chunk)
|
312
|
-
print "\n"
|
313
296
|
chunk.each_with_index do |content, i|
|
314
|
-
break if content.empty?
|
297
|
+
break if content.name.empty?
|
315
298
|
|
316
|
-
print " #{fetch_string(@input, content, *options(
|
317
|
-
print ' ' * (@max_widths[i] - content.length) unless @one_per_line || @long
|
299
|
+
print " #{fetch_string(@input, content, *options(content))}"
|
300
|
+
print ' ' * (@max_widths[i] - content.name.length) unless @one_per_line || @long
|
318
301
|
end
|
302
|
+
print "\n"
|
319
303
|
end
|
320
304
|
|
321
|
-
def options(
|
322
|
-
if
|
323
|
-
key = content.to_sym
|
305
|
+
def options(content)
|
306
|
+
if content.directory?
|
307
|
+
key = content.name.to_sym
|
324
308
|
color = @colors[:dir]
|
325
309
|
return [:folder, color, :folders] unless @all_folders.include?(key)
|
326
310
|
key = @folder_aliases[key] unless @folder_keys.include?(key)
|
@@ -330,7 +314,7 @@ module ColorLS
|
|
330
314
|
color = @colors[:recognized_file]
|
331
315
|
return [content.downcase.to_sym, color, :recognized_files] if @file_keys.include?(key)
|
332
316
|
|
333
|
-
key = content.split('.').last.downcase.to_sym
|
317
|
+
key = content.name.split('.').last.downcase.to_sym
|
334
318
|
return [:file, @colors[:unrecognized_file], :unrecognized_files] unless @all_files.include?(key)
|
335
319
|
|
336
320
|
key = @file_aliases[key] unless @file_keys.include?(key)
|
@@ -340,10 +324,10 @@ module ColorLS
|
|
340
324
|
def tree_traverse(path, prespace, indent)
|
341
325
|
contents = init_contents(path)
|
342
326
|
contents.each do |content|
|
343
|
-
icon = content == contents.last ||
|
327
|
+
icon = content == contents.last || content.directory? ? ' └──' : ' ├──'
|
344
328
|
print tree_branch_preprint(prespace, indent, icon).colorize(@colors[:tree])
|
345
|
-
print " #{fetch_string(path, content, *options(
|
346
|
-
next unless
|
329
|
+
print " #{fetch_string(path, content, *options(content))} \n"
|
330
|
+
next unless content.directory?
|
347
331
|
tree_traverse("#{path}/#{content}", prespace + indent, indent)
|
348
332
|
end
|
349
333
|
end
|