Inits repository

This commit is contained in:
Athitya 2017-06-29 22:08:38 +05:30
commit ad726bc083
5 changed files with 152 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
Gemfile.lock

4
Gemfile Normal file
View file

@ -0,0 +1,4 @@
source 'https://rubygems.org'
gem 'colorize'
gem 'facets'

54
aliases.yaml Normal file
View file

@ -0,0 +1,54 @@
apk: android
ds_store: apple
localized: apple
mp3: audio
scss: css
docx: doc
gdoc: doc
mobi: ebook
eot: font
otf: font
ttf: font
woff: font
editorconfig: git
gitconfig: git
gitignore: git
gitignore_global: git
jpeg: image
jpg: image
png: image
svg: image
markdown: md
mkd: md
rdoc: md
readme: md
license: md
pptx: ppt
gslides: ppt
pyc: py
rdata: r
rds: r
gemfile: rb
gemspec: rb
guardfile: rb
lock: rb
procfile: rb
rakefile: rb
rspec: rb
rspec_status: rb
rspec_parallel: rb
ru: rb
bash: sh
bashrc: sh
bash_history: sh
bash_profile: sh
zsh: sh
zsh-theme: sh
zshrc: sh
mp4: video
csv: xls
gsheet: xls
xlsx: xls
yaml: yml
rar: zip
tar: zip

60
colorls.rb Normal file
View file

@ -0,0 +1,60 @@
require 'colorize'
require 'yaml'
require 'facets'
# Source for icons unicode: http://nerdfonts.com/
class ColorLS
def initialize(input)
@input = input || Dir.pwd
@contents = Dir.entries(@input) - ['.', '..']
@count = { folders: 0, recognized_files: 0, unrecognized_files: 0 }
@formats = load_from_yaml('formats.yaml').symbolize_keys
@aliases = load_from_yaml('aliases.yaml')
.to_a
.map! { |k, v| [k.to_sym, v.to_sym] }
.to_h
@format_keys = @formats.keys
@aliase_keys = @aliases.keys
end
def ls
@contents.each { |content| print fetch_string(content, *options(content)) }
puts "\n\n\tFound #{@contents.length} contents in this directory"\
"\n\t#{File.expand_path(@input)}."\
"\n\n\t\tFolders\t\t\t: #{@count[:folders]}"\
"\n\t\tRecognized files\t: #{@count[:recognized_files]}"\
"\n\t\tUnrecognized files\t: #{@count[:unrecognized_files]}"
.colorize(:white)
end
private
def fetch_string(content, key, color, increment)
@count[increment] += 1
value = @formats[key]
logo = value.gsub(/\\u[\da-f]{4}/i) { |m| [m[-4..-1].to_i(16)].pack('U') }
"\n\t#{logo} #{content}".colorize(color)
end
def load_from_yaml(filename)
path = $PROGRAM_NAME.gsub('/colorls.rb', '')
YAML.safe_load(File.read("#{path}/#{filename}"))
end
def options(content)
return %i[folder blue folders] if Dir.exist?("#{@input}/#{content}")
all_keys = @format_keys + @aliase_keys
key = content.split('.').last.downcase.to_sym
return %i[file yellow unrecognized_files] unless all_keys.include?(key)
key = @aliases[key] unless @format_keys.include?(key)
[key, :green, :recognized_files]
end
end
ColorLS.new(ARGV[0]).ls
true

33
formats.yaml Normal file
View file

@ -0,0 +1,33 @@
android: "\uf17b"
apple: "\uf179"
audio: "\uf001"
avro: "\ue60b"
c: "\ue61e"
cpp: "\ue61d"
css: "\ue749"
doc: "\uf1c2"
ebook: "\ue28b"
file: "\uf15b"
folder: "\uf115"
font: "\uf031"
gform: "\uf298"
git: "\uf1d3"
html: "\uf13b"
image: "\uf1c5"
js: "\ue74e"
json: "\ue60b"
less: "\ue758"
md: "\uf48a"
ppt: "\uf1c4"
pdf: "\uf1c1"
py: "\ue606"
r: "\uf25d"
rb: "\ue21e"
rdb: "\ue76d"
sh: "\uf489"
txt: "\uf15c"
video: "\uf03d"
xls: "\uf1c3"
xml: "\ue619"
yml: "\uf481"
zip: "\uf410"