colorls 0.1.7 → 1.0.0

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: 1466b9e0c4a5e7e722f61b3bc23c72393c84b209
4
- data.tar.gz: 2e7fb89508e0e73a5ebf2c895d9054bb2961ea91
3
+ metadata.gz: 03284e40013cff842081767d4f8118e037ab5ecf
4
+ data.tar.gz: f9f342894cccb5dc7f5231e4273f8ebacf17877e
5
5
  SHA512:
6
- metadata.gz: 5e9549e3bb540525c3b7118eae86ac2b77bd4d325e5c0e1764866cc82274ffc80010b997b0996c9173f9b921afdbd4afcf1c364e0e67ccee3ec77161db1b43d4
7
- data.tar.gz: f8f3c48565b330c01dd075b8a1a9e056913d7d1079c196aa7adf350645c8d0fd9fc80264f3393d7334c212f8f168535cc6f8aba22ef332e1005b5cae7357a534
6
+ metadata.gz: 1597a907cc5fb9b4dc1a9e928d6ef514cd49d19f44ae8a9723382edb25b2652faf561fa238509351b8a0f41c94fb101c231dafe90c9368e24e2924a42a400f52
7
+ data.tar.gz: 9af5861331a7d00b3c3ee7336352cb17cb053b26b3d47e3fd6566950e16dcefece09b9c0e451e7e7c98dc067e85c050f46442c42d87c60980b3bea64bc58fbfe
@@ -45,10 +45,13 @@ Metrics/ModuleLength:
45
45
  Max: 200
46
46
 
47
47
  Metrics/ClassLength:
48
- Max: 250
48
+ Max: 300
49
49
 
50
50
  Metrics/ParameterLists:
51
- Max: 10
51
+ Max: 15
52
+
53
+ Naming/FileName:
54
+ Enabled: false
52
55
 
53
56
  Style/ParallelAssignment:
54
57
  Enabled: false
@@ -71,22 +74,22 @@ Layout/SpaceAroundOperators:
71
74
  Style/EmptyCaseCondition:
72
75
  Enabled: false
73
76
 
74
- Style/FileName:
75
- Enabled: false
76
-
77
77
  Style/MultilineBlockChain:
78
78
  Enabled: false
79
79
 
80
80
  # Current preferred metrics --------------------------------------------
81
81
  # Better values are encouraged, but not required.
82
82
  Metrics/AbcSize:
83
- Max: 20
83
+ Max: 30
84
84
 
85
85
  Metrics/MethodLength:
86
- Max: 15
86
+ Max: 20
87
87
 
88
88
  Metrics/CyclomaticComplexity:
89
- Max: 7
89
+ Max: 8
90
+
91
+ Metrics/PerceivedComplexity:
92
+ Max: 8
90
93
 
91
94
  # TODO -----------------------------------------------------------------
92
95
 
@@ -19,10 +19,14 @@ script:
19
19
  - colorls -f
20
20
  - colorls -l
21
21
  - colorls -l spec/fixtures/symlinks
22
+ - ( cd spec/fixtures ; colorls .hidden-file ) | fgrep '.hidden-file'
23
+ - colorls -l README.md
22
24
  - colorls -r
23
- - colorls -sd
24
- - colorls -sf
25
+ - colorls --sd
26
+ - colorls --sf
25
27
  - colorls -t
28
+ - colorls -h
29
+ - colorls --gs
26
30
  - colorls spec/fixtures/symlinks
27
31
  - colorls README.md
28
32
  - colorls *
@@ -28,6 +28,9 @@ Please proceed with a Pull Request only after you're assigned. It'd be sad if yo
28
28
  3. (Optional) To test whether `colorls` executable is working properly, do
29
29
  ```sh
30
30
  rake install
31
+ ```
32
+ Then install the gem file in the folder `pkg`. After that to use the new binary,
33
+ ```sh
31
34
  colorls # start using colorls
32
35
  ```
33
36
 
@@ -42,3 +45,5 @@ Please proceed with a Pull Request only after you're assigned. It'd be sad if yo
42
45
  bundle exec rubocop
43
46
  bundle exec rspec
44
47
  ```
48
+
49
+ 6. (Required for new flags) Add command to `.travis.yml` file.
@@ -0,0 +1,14 @@
1
+ # COVERAGES
2
+
3
+ A documentation of all the places on the World Wide Web, where `colorls` has been featured:
4
+
5
+ - [YouTube : File Icons on Linux Terminal](https://m.youtube.com/watch?v=NESi45Q2mHg)
6
+ - [GitHub : Awesome README](https://github.com/matiassingers/awesome-readme)
7
+ - [HackerNews : Colorls – A Ruby script that beautifies the terminal's ls command](https://news.ycombinator.com/item?id=14717341)
8
+ - [GitHub : A curated list of Terminal frameworks, plugins & resources for CLI lovers](https://github.com/k4m4/terminals-are-sexy)
9
+ - [Facebook : colorls story](https://m.facebook.com/story.php?story_fbid=1972265916349994&id=1884586571784596)
10
+ - [openruby : colorls a ruby script that beautifies the terminals ls](https://openruby.com/pages/98288680-colorls-a-ruby-script-that-beautifies-the-terminals-ls)
11
+ - [omgubuntu : add-bling-ls-bash-command-colorls](http://www.omgubuntu.co.uk/2017/07/add-bling-ls-bash-command-colorls)
12
+ - [GitHub : nerd-fonts](https://github.com/ryanoasis/nerd-fonts/wiki/Real-World-Mentions-&-Usage-(Sightings))
13
+ - [GitHub : Awesome Ruby](https://github.com/markets/awesome-ruby)
14
+ - [GitHub : Awesome Shell](https://github.com/uhub/awesome-shell)
@@ -0,0 +1,12 @@
1
+ ### Description
2
+
3
+ Thanks for opening this issue. Add a brief description of what this issue is, and how to recreate it. Do tag the relevant issue(s) and PR(s) below. If required, add some screenshot(s) to showcase the issue.
4
+
5
+ - Relevant Issues : (none)
6
+ - Relevant PRs : (none)
7
+ - Type of issue :
8
+ - [ ] Installation
9
+ - [ ] Font-related
10
+ - [ ] Feature request
11
+ - [ ] Bug in existing feature
12
+ - [ ] Developer mode : Code quality / Tests / Documentation
@@ -0,0 +1,12 @@
1
+ ### Description
2
+
3
+ Thanks for contributing this Pull Request. Add a brief description of what this Pull Request does. Do tag the relevant issue(s) and PR(s) below. If required, add some screenshot(s) to support your changes.
4
+
5
+ - Relevant Issues : (none)
6
+ - Relevant PRs : (none)
7
+ - Type of change :
8
+ - [ ] New feature
9
+ - [ ] Bug fix for existing feature
10
+ - [ ] Code quality improvement
11
+ - [ ] Addition or Improvement of tests
12
+ - [ ] Addition or Improvement of documentation
data/README.md CHANGED
@@ -6,9 +6,8 @@
6
6
  [![Gem Version](https://badge.fury.io/rb/colorls.svg)](https://badge.fury.io/rb/colorls)
7
7
  [![Build Status](https://travis-ci.org/athityakumar/colorls.svg?branch=master)](https://travis-ci.org/athityakumar/colorls)
8
8
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=shields)](http://makeapullrequest.com)
9
- [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)
10
9
 
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.
10
+ 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.
12
11
 
13
12
  ![Example #1](readme/usage1.png)
14
13
 
@@ -19,6 +18,7 @@ A Ruby script that colorizes the `ls` output with color and icons. Here are the
19
18
  - [Usage](#usage)
20
19
  - [Installation](#installation)
21
20
  - [Recommended configurations](#recommended-configurations)
21
+ - [Custom configurations](#custom-configurations)
22
22
  - [Updating](#updating)
23
23
  - [Uninstallation](#uninstallation)
24
24
  - [Contributing](#contributing)
@@ -28,15 +28,15 @@ A Ruby script that colorizes the `ls` output with color and icons. Here are the
28
28
 
29
29
  [(Back to top)](#table-of-contents)
30
30
 
31
- - Just `lc` : Prints all directories, files and dotfiles in current directory.
31
+ - With `-a` : `lc` prints all directories, files and dotfiles in current directory.
32
32
 
33
33
  ![Usage #1](readme/usage1.png)
34
34
 
35
- - With paths : `lc path(s)` prints all directories, files and dotfiles in given directory / directories.
35
+ - With paths : `lc path(s) -a` prints all directories, files and dotfiles in given directory / directories.
36
36
 
37
37
  ![Usage #2](readme/usage2.png)
38
38
 
39
- - With `--report` or `-r` flag : `lc path(s) -r` : Prints all directories, files and dotfiles in directories, along with a brief report about number of files and folders shown.
39
+ - With `--report` or `-r` flag : `lc path(s) -r -a` : Prints all directories, files and dotfiles in directories, along with a brief report about number of files and folders shown.
40
40
 
41
41
  ![Usage #3](readme/usage3.png)
42
42
  ![Usage #4](readme/usage4.png)
@@ -55,14 +55,16 @@ A Ruby script that colorizes the `ls` output with color and icons. Here are the
55
55
 
56
56
  ![Usage #9](readme/usage9.png)
57
57
 
58
+ - Additional flags: `--almost_all` or `-A`, `--long` or `-l`, `--tree` or `-t`
59
+
58
60
  # Installation
59
61
 
60
62
  [(Back to top)](#table-of-contents)
61
63
 
62
- 1. Install Ruby (prefably, version > 2.1)
63
- 2. Install the patched fonts of powerline nerd-font and/or font-awesome. Have a look at [nerdfont's README](https://github.com/ryanoasis/nerd-fonts/blob/master/readme.md) for more installation instructions.
64
+ 1. Install Ruby (preferably, version > 2.1)
65
+ 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.
64
66
 
65
- *Note for `iTerm2` users - Please enable the nerd-font at iTerm2 > Preferences > Profiles > Text > Non-Ascii font > Knack Regular Nerd Font Complete.*
67
+ *Note for `iTerm2` users - Please enable the Nerd Font at iTerm2 > Preferences > Profiles > Text > Non-ASCII font > Knack Regular Nerd Font Complete.*
66
68
 
67
69
  3. Install the [colorls](https://rubygems.org/gems/colorls/) ruby gem with `gem install colorls`
68
70
 
@@ -88,9 +90,25 @@ A Ruby script that colorizes the `ls` output with color and icons. Here are the
88
90
  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`)
89
91
 
90
92
  ```sh
91
- subl $(gem which colorls)/../yaml/
93
+ subl $(dirname $(gem which colorls))/yaml
92
94
  ```
93
95
 
96
+ # Custom configurations
97
+
98
+ [(Back to top)](#table-of-contents)
99
+
100
+ You can overwrite the existing icons and colors mapping by creating yaml files in ~/.config/lscolors.
101
+
102
+ Each .yaml file inside the lib/colorls/yaml directory of this repo can be overwrited.
103
+
104
+ Let's say you want to add an icon for swift files, you might create a `files.yaml` inside `~/.config/lscolors` and add the following:
105
+
106
+ ```
107
+ swift: "\uF179"
108
+ ```
109
+
110
+ Which will add the Apple logo to swift files.
111
+
94
112
  # Updating
95
113
 
96
114
  [(Back to top)](#table-of-contents)
@@ -0,0 +1,20 @@
1
+ # Release Policy
2
+
3
+ Applicable from colorls v1.0.0 onwards
4
+
5
+ ### Versioning
6
+
7
+ Colorls follows semantic versioning whereby the version number is always in the form MAJOR.MINOR.PATCH
8
+
9
+ - Patch bump : Bug fixes
10
+ - Minor bump : New features (with backwards compatibility)
11
+ - Major bump : API breaking changes
12
+
13
+ For Major and Minor bumps release candidates should be released around 2 weeks prior to the bump and are indicated by MAJOR.MINOR.0.rc.
14
+
15
+ For more information see the full semantic versioning specification at http://semver.org/.
16
+
17
+ ### Release Timing
18
+
19
+ Patch releases should be done after every fix of a major bug (as tagged in the github issue tracker).
20
+ Major releases should be kept to the minimum.
data/Rakefile CHANGED
@@ -1,6 +1,11 @@
1
- require 'bundler/gem_tasks'
1
+ require 'bundler/setup'
2
+ require 'rubygems/tasks'
3
+ Gem::Tasks.new
4
+
2
5
  require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new
3
7
 
4
- RSpec::Core::RakeTask.new(:spec)
8
+ require 'rubocop/rake_task'
9
+ RuboCop::RakeTask.new
5
10
 
6
- task default: :spec
11
+ task default: %w[spec rubocop]
@@ -1,5 +1,3 @@
1
- # coding: utf-8
2
-
3
1
  lib = File.expand_path('../lib', __FILE__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
  require 'colorls/version'
@@ -21,14 +19,29 @@ Gem::Specification.new do |spec|
21
19
  spec.executables = 'colorls'
22
20
  spec.require_paths = ['lib']
23
21
 
22
+ spec.post_install_message = <<-EOF
23
+ *************************************************************************
24
+ Changes introduced in colorls-v1.0.0
25
+
26
+ Sort by dirs : -sd flag has been renamed to --sd
27
+ Sort by files : -sf flag has been renamed to --sf
28
+ Git status : -gs flag has been renamed to --gs
29
+
30
+ Clubbed flags : `colorls -ald` works
31
+ Help menu : `colorls -h` provides all possible flag options
32
+ *************************************************************************
33
+ EOF
34
+
24
35
  spec.add_runtime_dependency 'colorize'
25
36
  spec.add_runtime_dependency 'facets'
26
- spec.add_runtime_dependency 'ruby-terminfo'
27
37
  spec.add_runtime_dependency 'filesize'
38
+ spec.add_runtime_dependency 'git'
39
+ spec.add_runtime_dependency 'ruby-terminfo'
28
40
 
29
41
  spec.add_development_dependency 'bundler', '~> 1.15'
42
+ spec.add_development_dependency 'diffy'
30
43
  spec.add_development_dependency 'rake'
31
44
  spec.add_development_dependency 'rspec'
32
45
  spec.add_development_dependency 'rubocop'
33
- spec.add_development_dependency 'diffy'
46
+ spec.add_development_dependency 'rubygems-tasks'
34
47
  end
@@ -4,6 +4,7 @@ require 'facets'
4
4
  require 'terminfo'
5
5
  require 'etc'
6
6
  require 'filesize'
7
+ require 'git'
7
8
 
8
9
  require 'colorls/core'
9
10
  require 'colorls/flags'
@@ -1,7 +1,7 @@
1
1
  module ColorLS
2
2
  class Core
3
3
  def initialize(input=nil, all: false, report: false, sort: false, show: false,
4
- one_per_line: false, long: false, almost_all: false, tree: false, colors: [])
4
+ one_per_line: false, git_status: false,long: false, almost_all: false, tree: false, colors: [])
5
5
  @input = input || Dir.pwd
6
6
  @count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
7
7
  @all = all
@@ -12,6 +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
16
  @screen_width = ::TermInfo.screen_size.last
16
17
  @colors = colors
17
18
 
@@ -33,20 +34,21 @@ module ColorLS
33
34
  end
34
35
  print "\n"
35
36
  display_report if @report
36
-
37
37
  true
38
38
  end
39
39
 
40
40
  private
41
41
 
42
42
  def init_contents(path)
43
- @contents = if Dir.exist?(path)
43
+ is_directory = Dir.exist?(path)
44
+ @contents = if is_directory
44
45
  Dir.entries(path)
45
46
  else
46
- [path]
47
+ @input = File.dirname(path)
48
+ [File.basename(path)]
47
49
  end
48
50
 
49
- filter_hidden_contents
51
+ filter_hidden_contents if is_directory
50
52
  filter_contents(path) if @show
51
53
  sort_contents(path) if @sort
52
54
 
@@ -149,8 +151,7 @@ module ColorLS
149
151
  end
150
152
 
151
153
  def in_line(chunk_size)
152
- return false if @max_widths.sum + 8 * chunk_size > @screen_width
153
- true
154
+ (@max_widths.sum + 12 * chunk_size <= @screen_width)
154
155
  end
155
156
 
156
157
  def display_report
@@ -202,27 +203,50 @@ module ColorLS
202
203
 
203
204
  def size_info(stat)
204
205
  size = Filesize.from("#{stat.size} B").pretty.split(' ')
205
- "#{size[0][0..-4].rjust(3,' ')} #{size[1].ljust(3,' ')}".colorize(@colors[:normal])
206
+ size = "#{size[0][0..-4].rjust(3,' ')} #{size[1].ljust(3,' ')}"
207
+ return size.colorize(@colors[:file_large]) if stat.size >= 512 * 1024 ** 2
208
+ return size.colorize(@colors[:file_medium]) if stat.size >= 128 * 1024 ** 2
209
+ size.colorize(@colors[:file_small])
206
210
  end
207
211
 
208
212
  def mtime_info(stat)
209
- mtime = stat.mtime.asctime.colorize(@colors[:no_modifier])
210
- mtime = mtime.colorize(@colors[:day_old]) if Time.now - stat.mtime < 24 * 60 * 60
211
- mtime = mtime.colorize(@colors[:hour_old]) if Time.now - stat.mtime < 60 * 60
212
- mtime
213
+ mtime = stat.mtime.asctime
214
+ return mtime.colorize(@colors[:hour_old]) if Time.now - stat.mtime < 60 * 60
215
+ return mtime.colorize(@colors[:day_old]) if Time.now - stat.mtime < 24 * 60 * 60
216
+ mtime.colorize(@colors[:no_modifier])
217
+ end
218
+
219
+ def git_info(path, content)
220
+ return '' unless @git_status
221
+ until File.exist?('.git') # check whether the repository is git controlled
222
+ return '' if Dir.pwd=='/'
223
+ Dir.chdir('..')
224
+ end
225
+
226
+ relative_path = path.remove(Dir.pwd+'/')
227
+ relative_path = relative_path==path ? '' : relative_path+'/'
228
+
229
+ status = Git.open('.').status
230
+ return '(A)'.colorize(:green) if status.added.keys.any? { |a| a.include?("#{relative_path}#{content}") }
231
+ return '(U)'.colorize(:red) if status.untracked.keys.any? { |u| u.include?("#{relative_path}#{content}") }
232
+ return '(C)'.colorize(:yellow) if status.changed.keys.any? { |c| c.include?("#{relative_path}#{content}") }
233
+ '(-)'
213
234
  end
214
235
 
215
236
  def long_info(path, content)
216
237
  return '' unless @long
238
+ @git_status = true
217
239
  unless File.exist?("#{path}/#{content}")
218
240
  return '[No Info]'.colorize(@colors[:error]) + ' ' * (39 + @userlength + @grouplength)
219
241
  end
220
242
  stat = File.stat("#{path}/#{content}")
221
- [mode_info(stat), user_info(stat), group_info(stat), size_info(stat), mtime_info(stat)].join(' ')
243
+ @git_status = false
244
+ [mode_info(stat), user_info(stat), group_info(stat), size_info(stat), mtime_info(stat),git_info(path,content)]
245
+ .join(' ')
222
246
  end
223
247
 
224
248
  def symlink_info(path, content)
225
- return '' unless @long && File.lstat("#{path}/#{content}").symlink?
249
+ return '' unless @long && File.symlink?("#{path}/#{content}")
226
250
  if File.exist?("#{path}/#{content}")
227
251
  " ⇒ #{File.readlink("#{path}/#{content}")}/".colorize(@colors[:link])
228
252
  else
@@ -241,9 +265,10 @@ module ColorLS
241
265
 
242
266
  [
243
267
  long_info(path, content),
268
+ "#{git_info(path,content)} ",
244
269
  logo.colorize(color),
245
- "#{content.colorize(color)}#{slash?(path, content)}#{symlink_info(path, content)}"
246
- ].join(' ')
270
+ " #{content.colorize(color)}#{slash?(path, content)}#{symlink_info(path, content)}"
271
+ ].join
247
272
  end
248
273
 
249
274
  def ls_line(chunk)
@@ -1,30 +1,42 @@
1
+ require 'optparse'
2
+ require 'colorls/version'
3
+
1
4
  module ColorLS
2
5
  class Flags
3
6
  def initialize(*args)
4
7
  @args = args
5
- set_color_opts
8
+ @light_colors = false
9
+ @mode = :one_per_line unless STDOUT.tty?
6
10
 
7
11
  @opts = {
8
- show: fetch_show_opts,
9
- sort: fetch_sort_opts,
10
- all: flag_given?(%w[-a --all]),
11
- almost_all: flag_given?(%w[-A --almost-all]),
12
- report: flag_given?(%w[-r --report]),
13
- one_per_line: flag_given?(%w[-1]) || !STDOUT.tty?,
14
- long: flag_given?(%w[-l --long]),
15
- tree: flag_given?(%w[-t --tree]),
16
- colors: @colors
12
+ show: false,
13
+ sort: false,
14
+ all: false,
15
+ almost_all: false,
16
+ report: false,
17
+ git_status: false,
18
+ colors: []
17
19
  }
18
20
 
19
- @args.keep_if { |arg| !arg.start_with?('-') }
21
+ parse_options
22
+
23
+ # handle mutual exclusive options
24
+ %i[tree long one_per_line].each do |value|
25
+ @opts[value] = @mode == value
26
+ end
27
+
28
+ return unless @mode == :tree
29
+
30
+ # FIXME: `--all` and `--tree` do not work together, use `--almost-all` instead
31
+ @opts[:almost_all] = true if @opts[:all]
32
+ @opts[:all] = false
33
+
34
+ # `--tree` does not support reports
35
+ @opts[:report] = false
20
36
  end
21
37
 
22
38
  def process
23
- incompatible = report_incompatible_flags
24
- return STDERR.puts "\n #{incompatible}".colorize(:red) if incompatible
25
-
26
39
  return Core.new(@opts).ls if @args.empty?
27
-
28
40
  @args.each do |path|
29
41
  next STDERR.puts "\n Specified path '#{path}' doesn't exist.".colorize(:red) unless File.exist?(path)
30
42
  Core.new(path, @opts).ls
@@ -33,66 +45,89 @@ module ColorLS
33
45
 
34
46
  private
35
47
 
36
- def flag_given?(flags)
37
- flags.each { |flag| return true if @args.include?(flag) }
38
- false
48
+ def add_sort_options(options)
49
+ options.separator ''
50
+ options.separator 'sorting options:'
51
+ options.separator ''
52
+ options.on('--sd', '--sort-dirs', '--group-directories-first', 'sort directories first') { @opts[:sort] = :dirs }
53
+ options.on('--sf', '--sort-files', 'sort files first') { @opts[:sort] = :files }
39
54
  end
40
55
 
41
- def set_color_opts
42
- light_colors = flag_given? %w[--light]
43
- dark_colors = flag_given? %w[--dark]
44
-
45
- if light_colors && dark_colors
46
- @colors = ColorLS.load_from_yaml('dark_colors.yaml', true)
47
- STDERR.puts "\n Restrain from using --light and --dark flags together."
48
- .colorize(@colors[:error])
49
- elsif light_colors
50
- @colors = ColorLS.load_from_yaml('light_colors.yaml', true)
51
- else # default colors
52
- @colors = ColorLS.load_from_yaml('dark_colors.yaml', true)
53
- end
54
-
55
- @colors
56
+ def add_common_options(options)
57
+ options.on('-a', '--all', 'do not ignore entries starting with .') { @opts[:all] = true }
58
+ options.on('-A', '--almost-all', 'do not list . and ..') { @opts[:almost_all] = true }
59
+ options.on('-l', '--long', 'use a long listing format') { @mode = :long }
60
+ options.on('-t', '--tree', 'shows tree view of the directory') { @mode = :tree }
61
+ options.on('-r', '--report', 'show brief report') { @opts[:report] = true }
62
+ options.on('-1', 'list one file per line') { @mode = :one_per_line }
63
+ options.on('-d', '--dirs', 'show only directories') { @opts[:show] = :dirs }
64
+ options.on('-f', '--files', 'show only files') { @opts[:show] = :files }
65
+ options.on('--gs', '--git-status', 'show git status for each file') { @opts[:git_status] = true }
56
66
  end
57
67
 
58
- def fetch_show_opts
59
- show_dirs_only = flag_given? %w[-d --dirs]
60
- show_files_only = flag_given? %w[-f --files]
61
-
62
- if show_files_only && show_dirs_only
63
- STDERR.puts "\n Restrain from using -d and -f flags together."
64
- .colorize(@colors[:error])
65
- return nil
66
- else
67
- return :files if show_files_only
68
- return :dirs if show_dirs_only
69
- false
70
- end
68
+ def add_general_options(options)
69
+ options.separator ''
70
+ options.separator 'general options:'
71
+
72
+ options.separator ''
73
+ options.on('--light', 'use light color scheme') { @light_colors = true }
74
+ options.on('--dark', 'use dark color scheme') { @light_colors = false }
71
75
  end
72
76
 
73
- def fetch_sort_opts
74
- sort_dirs_first = flag_given? %w[-sd --sort-dirs]
75
- sort_files_first = flag_given? %w[-sf --sort-files]
76
-
77
- if sort_dirs_first && sort_files_first
78
- STDERR.puts "\n Restrain from using -sd and -sf flags together."
79
- .colorize(@colors[:error])
80
- return nil
81
- else
82
- return :files if sort_files_first
83
- return :dirs if sort_dirs_first
84
- false
85
- end
77
+ def show_examples
78
+ puts <<EXAMPLES.gsub(/^ /, '')
79
+
80
+ examples:
81
+
82
+ * show the given file:
83
+
84
+ #{'colorls README.md'.colorize(:green)}
85
+
86
+ * show matching files and list matching directories:
87
+
88
+ #{'colorls *'.colorize(:green)}
89
+
90
+ * filter output by a regular expression:
91
+
92
+ #{'colorls | grep PATTERN'.colorize(:green)}
93
+
94
+ * several short options can be combined:
95
+
96
+ #{'colorls -d -l -a'.colorize(:green)}
97
+ #{'colorls -dla'.colorize(:green)}
98
+
99
+ EXAMPLES
86
100
  end
87
101
 
88
- def report_incompatible_flags
89
- return '' if @opts[:show].nil? || @opts[:sort].nil?
102
+ def parse_options
103
+ parser = OptionParser.new do |opts|
104
+ opts.banner = 'Usage: colorls [OPTION]... [FILE]...'
105
+ opts.separator ''
106
+
107
+ add_common_options(opts)
108
+ add_sort_options(opts)
109
+ add_general_options(opts)
110
+
111
+ opts.separator ''
112
+ opts.on_tail('-h', '--help', 'prints this help') do
113
+ puts parser
114
+ show_examples
115
+ exit
116
+ end
117
+ opts.on_tail('--version', 'show version') do
118
+ puts ColorLS::VERSION
119
+ exit
120
+ end
121
+ end
90
122
 
91
- return 'Restrain from using -t (--tree) and -r (--report) flags together.' if @opts[:tree] && @opts[:report]
123
+ parser.parse!(@args)
92
124
 
93
- return 'Restrain from using -t (--tree) and -a (--all) flags together.' if @opts[:tree] && @opts[:all]
125
+ set_color_opts
126
+ end
94
127
 
95
- nil
128
+ def set_color_opts
129
+ color_scheme_file = @light_colors ? 'light_colors.yaml' : 'dark_colors.yaml'
130
+ @opts[:colors] = ColorLS.load_from_yaml(color_scheme_file, true)
96
131
  end
97
132
  end
98
133
  end
@@ -1,11 +1,22 @@
1
1
  module ColorLS
2
2
  def self.load_from_yaml(filename, aliase=false)
3
- filepath = File.join(File.dirname(__FILE__),"../yaml/#{filename}")
4
- yaml = YAML.safe_load(File.read(filepath)).symbolize_keys
3
+ user_config_filepath = File.join(Dir.home, ".config/colorls/#{filename}")
4
+ filepath = File.join(File.dirname(__FILE__),"../yaml/#{filename}")
5
+ yaml = read_file(filepath)
6
+
7
+ if File.exist?(user_config_filepath)
8
+ user_config_yaml = read_file(user_config_filepath)
9
+ yaml = yaml.merge(user_config_yaml)
10
+ end
11
+
5
12
  return yaml unless aliase
6
13
  yaml
7
14
  .to_a
8
15
  .map! { |k, v| [k, v.to_sym] }
9
16
  .to_h
10
17
  end
18
+
19
+ def self.read_file(filepath)
20
+ YAML.safe_load(File.read(filepath)).symbolize_keys
21
+ end
11
22
  end
@@ -1,3 +1,3 @@
1
1
  module ColorLS
2
- VERSION = '0.1.7'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -18,6 +18,11 @@ day_old: yellow
18
18
  hour_old: green
19
19
  no_modifier: white
20
20
 
21
+ # File Size
22
+ file_large: red
23
+ file_medium: yellow
24
+ file_small: green
25
+
21
26
  # Random
22
27
  report: white
23
28
  user: green
@@ -3,6 +3,8 @@ gradle: android
3
3
  ds_store: apple
4
4
  localized: apple
5
5
  mp3: audio
6
+ ogg: audio
7
+ editorconfig: conf
6
8
  scss: css
7
9
  docx: doc
8
10
  gdoc: doc
@@ -11,7 +13,7 @@ eot: font
11
13
  otf: font
12
14
  ttf: font
13
15
  woff: font
14
- editorconfig: git
16
+ woff2: font
15
17
  gitconfig: git
16
18
  gitignore: git
17
19
  gitignore_global: git
@@ -25,6 +27,7 @@ png: image
25
27
  svg: image
26
28
  jar: java
27
29
  properties: json
30
+ tsx: jsx
28
31
  license: md
29
32
  markdown: md
30
33
  mkd: md
@@ -45,6 +48,8 @@ rspec: rb
45
48
  rspec_parallel: rb
46
49
  rspec_status: rb
47
50
  ru: rb
51
+ erb: rubydoc
52
+ slim: rubydoc
48
53
  bash: shell
49
54
  bash_history: shell
50
55
  bash_profile: shell
@@ -54,8 +59,13 @@ sh: shell
54
59
  zsh: shell
55
60
  zsh-theme: shell
56
61
  zshrc: shell
62
+ stylus: styl
57
63
  cls: tex
64
+ avi: video
65
+ mkv: video
58
66
  mp4: video
67
+ ogv: video
68
+ webm: video
59
69
  bat: windows
60
70
  exe: windows
61
71
  ini: windows
@@ -15,6 +15,7 @@ db: "\uf1c0"
15
15
  diff: "\uf440"
16
16
  doc: "\uf1c2"
17
17
  ebook: "\ue28b"
18
+ env: "\uf462"
18
19
  epub: "\ue28a"
19
20
  erl: "\ue7b1"
20
21
  file: "\uf15b"
@@ -22,7 +23,7 @@ font: "\uf031"
22
23
  gform: "\uf298"
23
24
  git: "\uf1d3"
24
25
  go: "\ue626"
25
- gruntfile.js: "\ue74c"
26
+ gruntfile.js: "\ue74c"
26
27
  hs: "\ue777"
27
28
  html: "\uf13b"
28
29
  image: "\uf1c5"
@@ -30,6 +31,7 @@ iml: "\ue7b5"
30
31
  java: "\ue204"
31
32
  js: "\ue74e"
32
33
  json: "\ue60b"
34
+ jsx: "\ue7ba"
33
35
  less: "\ue758"
34
36
  log: "\uf18d"
35
37
  lua: "\ue620"
@@ -46,6 +48,8 @@ r: "\uf25d"
46
48
  rb: "\ue21e"
47
49
  rdb: "\ue76d"
48
50
  rss: "\uf09e"
51
+ rubydoc: "\ue73b"
52
+ sass: "\ue603"
49
53
  scala: "\ue737"
50
54
  shell: "\uf489"
51
55
  sqlite3: "\ue7c4"
@@ -1,8 +1,11 @@
1
- .git: "\uf408"
1
+ .atom: "\ue764"
2
+ .git: "\uf1d3"
3
+ .github: "\uf408"
2
4
  .rvm: "\ue21e"
3
5
  .Trash: "\uf1f8"
6
+ .vscode: "\ue70c"
4
7
  config: "\ue5fc"
5
8
  folder: "\uf115"
6
9
  hidden: "\uf023"
7
10
  lib: "\uf121"
8
- node_modules: "\ue718"
11
+ node_modules: "\ue718"
@@ -18,6 +18,11 @@ day_old: yellow
18
18
  hour_old: green
19
19
  no_modifier: black
20
20
 
21
+ # File Size
22
+ file_large: red
23
+ file_medium: yellow
24
+ file_small: green
25
+
21
26
  # Random
22
27
  report: black
23
28
  user: green
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: 0.1.7
4
+ version: 1.0.0
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-07-14 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: ruby-terminfo
42
+ name: filesize
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,21 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: filesize
56
+ name: git
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-terminfo
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '1.15'
97
+ - !ruby/object:Gem::Dependency
98
+ name: diffy
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: rake
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -123,7 +151,7 @@ dependencies:
123
151
  - !ruby/object:Gem::Version
124
152
  version: '0'
125
153
  - !ruby/object:Gem::Dependency
126
- name: diffy
154
+ name: rubygems-tasks
127
155
  requirement: !ruby/object:Gem::Requirement
128
156
  requirements:
129
157
  - - ">="
@@ -149,9 +177,13 @@ files:
149
177
  - ".travis.yml"
150
178
  - CODE_OF_CONDUCT.md
151
179
  - CONTRIBUTING.md
180
+ - COVERAGES.md
152
181
  - Gemfile
182
+ - ISSUE_TEMPLATE.md
153
183
  - LICENSE.md
184
+ - PULL_REQUEST_TEMPLATE.md
154
185
  - README.md
186
+ - RELEASE_POLICY.md
155
187
  - Rakefile
156
188
  - colorls.gemspec
157
189
  - exe/colorls
@@ -180,7 +212,17 @@ homepage: https://github.com/athityakumar/colorls
180
212
  licenses:
181
213
  - MIT
182
214
  metadata: {}
183
- post_install_message:
215
+ post_install_message: |
216
+ *************************************************************************
217
+ Changes introduced in colorls-v1.0.0
218
+
219
+ Sort by dirs : -sd flag has been renamed to --sd
220
+ Sort by files : -sf flag has been renamed to --sf
221
+ Git status : -gs flag has been renamed to --gs
222
+
223
+ Clubbed flags : `colorls -ald` works
224
+ Help menu : `colorls -h` provides all possible flag options
225
+ *************************************************************************
184
226
  rdoc_options: []
185
227
  require_paths:
186
228
  - lib