Adds ruby gem skeleton

This commit is contained in:
Athitya 2017-07-05 19:53:11 +05:30
parent 64d256efad
commit f993755f0e
15 changed files with 239 additions and 65 deletions

94
.rubocop.yml Normal file
View file

@ -0,0 +1,94 @@
AllCops:
Include:
- 'lib/**/*'
Exclude:
- 'vendor/**/*'
- 'benchmarks/*'
- 'profile/*'
- 'lib/yaml/*'
DisplayCopNames: true
TargetRubyVersion: 2.1
# Preferred codebase style ---------------------------------------------
Layout/ExtraSpacing:
AllowForAlignment: true
Style/FormatString:
EnforcedStyle: percent
Style/AndOr:
EnforcedStyle: conditionals
Layout/SpaceAroundEqualsInParameterDefault:
EnforcedStyle: no_space
Layout/SpaceInsideBlockBraces:
EnforcedStyle: space
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space
Layout/AlignParameters:
EnforcedStyle: with_fixed_indentation
Style/EmptyElse:
EnforcedStyle: empty
Metrics/BlockLength:
Exclude:
- 'spec/**/*'
Metrics/LineLength:
Max: 120
Metrics/ModuleLength:
Max: 200
Metrics/ClassLength:
Max: 200
Metrics/ParameterLists:
Max: 10
Style/ParallelAssignment:
Enabled: false
Style/DoubleNegation:
Enabled: false
Style/SingleLineBlockParams:
Enabled: false
Style/PerlBackrefs:
Enabled: false
Layout/SpaceAfterComma:
Enabled: false
Layout/SpaceAroundOperators:
Enabled: false
Style/EmptyCaseCondition:
Enabled: false
Style/FileName:
Enabled: false
Style/MultilineBlockChain:
Enabled: false
# Current preferred metrics --------------------------------------------
# Better values are encouraged, but not required.
Metrics/AbcSize:
Max: 20
Metrics/MethodLength:
Max: 15
Metrics/CyclomaticComplexity:
Max: 7
# TODO -----------------------------------------------------------------
Style/Documentation:
Enabled: false

View file

@ -1,6 +1,3 @@
source 'https://rubygems.org'
gem 'colorize'
gem 'facets'
gem 'rubocop'
gem 'ruby-terminfo'
gemspec

21
LICENSE.txt Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2017 Athitya
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

6
Rakefile Normal file
View file

@ -0,0 +1,6 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task default: :spec

32
colorls.gemspec Normal file
View file

@ -0,0 +1,32 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'colorls/version'
Gem::Specification.new do |spec|
spec.name = 'colorls'
spec.version = ColorLS::VERSION
spec.authors = ['Athitya']
spec.email = ['athityakumar@gmail.com']
spec.summary = "A Ruby CLI gem that beautifies the terminal's ls command, with color and font-awesome icons."
spec.homepage = 'https://github.com/athityakumar/colorls'
spec.license = 'MIT'
spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.bindir = 'exe'
spec.executables = 'lc'
spec.require_paths = ['lib']
spec.add_runtime_dependency 'colorize'
spec.add_runtime_dependency 'facets'
spec.add_runtime_dependency 'ruby-terminfo'
spec.add_development_dependency 'bundler', '~> 1.15'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'rubocop'
end

55
exe/lc Executable file
View file

@ -0,0 +1,55 @@
#!/usr/bin/env ruby
require 'colorls'
args = *ARGV
opts = {}
opts[:report] = args.include?('-r') || args.include?('--report')
opts[:one_per_line] = args.include?('-1')
show_dirs_only = args.include?('-d') || args.include?('--dirs')
show_files_only = args.include?('-f') || args.include?('--files')
sort_dirs_first = args.include?('-sd') || args.include?('--sort-dirs')
sort_files_first = args.include?('-sf') || args.include?('--sort-files')
if sort_dirs_first && sort_files_first
STDERR.puts "\n Restrain from using -sd and -sf flags together."
.colorize(:red)
return
end
if show_files_only && show_dirs_only
STDERR.puts "\n Restrain from using -d and -f flags together."
.colorize(:red)
return
end
opts[:sort] = if sort_files_first
:files
elsif sort_dirs_first
:dirs
end
opts[:show] = if show_files_only
:files
elsif show_dirs_only
:dirs
end
args.keep_if { |arg| !arg.start_with?('-') }
if args.empty?
ColorLS.new(opts).ls
else
args.each do |path|
if Dir.exist?(path)
ColorLS.new(path, opts).ls
else
next STDERR.puts "\n Specified directory '#{path}' doesn't exist."
.colorize(:red)
end
end
end
true

69
colorls.rb → lib/colorls.rb Executable file → Normal file
View file

@ -1,4 +1,4 @@
#!/usr/bin/env ruby
require 'colorls/version'
require 'colorize'
require 'yaml'
@ -6,15 +6,15 @@ require 'facets'
require 'terminfo'
# Source for icons unicode: http://nerdfonts.com/
class ColorLS # rubocop:disable ClassLength
def initialize(input = nil, report:, sort:, show:, one_per_line:)
class ColorLS
def initialize(input=nil, report:, sort:, show:, one_per_line:)
@input = input || Dir.pwd
@count = { folders: 0, recognized_files: 0, unrecognized_files: 0 }
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
@report = report
@sort = sort
@show = show
@one_per_line = one_per_line
@screen_width = TermInfo.screen_size.last
@screen_width = ::TermInfo.screen_size.last
init_contents
@max_widths = @contents.map(&:length)
@ -128,10 +128,9 @@ class ColorLS # rubocop:disable ClassLength
"#{logo} #{content}".colorize(color)
end
def load_from_yaml(filename, aliase = false)
prog = $PROGRAM_NAME
path = prog.include?('/colorls.rb') ? prog.gsub('/colorls.rb', '') : '.'
yaml = YAML.safe_load(File.read("#{path}/#{filename}")).symbolize_keys
def load_from_yaml(filename, aliase=false)
filepath = File.join(File.dirname(__FILE__),"yaml/#{filename}")
yaml = YAML.safe_load(File.read(filepath)).symbolize_keys
return yaml unless aliase
yaml
.to_a
@ -166,55 +165,3 @@ class ColorLS # rubocop:disable ClassLength
[key, :green, :recognized_files]
end
end
args = *ARGV
opts = {}
opts[:report] = args.include?('-r') || args.include?('--report')
opts[:one_per_line] = args.include?('-1')
show_dirs_only = args.include?('-d') || args.include?('--dirs')
show_files_only = args.include?('-f') || args.include?('--files')
sort_dirs_first = args.include?('-sd') || args.include?('--sort-dirs')
sort_files_first = args.include?('-sf') || args.include?('--sort-files')
if sort_dirs_first && sort_files_first
STDERR.puts "\n Restrain from using -sd and -sf flags together."
.colorize(:red)
return
end
if show_files_only && show_dirs_only
STDERR.puts "\n Restrain from using -d and -f flags together."
.colorize(:red)
return
end
opts[:sort] = if sort_files_first
:files
elsif sort_dirs_first
:dirs
end
opts[:show] = if show_files_only
:files
elsif show_dirs_only
:dirs
end
args.keep_if { |arg| !arg.start_with?('-') }
if args.empty?
ColorLS.new(opts).ls
else
args.each do |path|
if Dir.exist?(path)
ColorLS.new(path, opts).ls
else
next STDERR.puts "\n Specified directory '#{path}' doesn't exist."
.colorize(:red)
end
end
end
true

3
lib/colorls/version.rb Normal file
View file

@ -0,0 +1,3 @@
module ColorLS
VERSION = '0.1.0'.freeze
end

BIN
pkg/colorls-0.1.0.gem Normal file

Binary file not shown.

5
spec/colorls_spec.rb Normal file
View file

@ -0,0 +1,5 @@
RSpec.describe ColorLS do
it 'has a version number' do
expect(ColorLS::VERSION).not_to be nil
end
end

14
spec/spec_helper.rb Normal file
View file

@ -0,0 +1,14 @@
require 'bundler/setup'
require 'colorls'
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = '.rspec_status'
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
config.expect_with :rspec do |c|
c.syntax = :expect
end
end