cgrep 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b7f38e3dc45de2e6b4139d3ae577d7af6c98020a
4
+ data.tar.gz: 98a7416a1aea6b9ab0ff387a1f21b3a8ac62b52c
5
+ SHA512:
6
+ metadata.gz: e75db1b51fe8f346577468a9dfc9aaef05741cab24a248ade12f7fc5e7e1c2419fad9973cec062d92fe8fd4f82b972e7b4ef739da40bfca7065d6068cb3a36df
7
+ data.tar.gz: eeb9656b771810120f2313b1ed1a2db170193c97c0889768bb27a8544a571ee6a697dda8c4245d5ccb987155db7183c599278d53e01e50e8fe2ee98fdeb0aeea
data/.gitignore ADDED
@@ -0,0 +1,92 @@
1
+
2
+ # Created by https://www.gitignore.io/api/git,vim,ruby
3
+ # Edit at https://www.gitignore.io/?templates=git,vim,ruby
4
+
5
+ ### Git ###
6
+ # Created by git for backups. To disable backups in Git:
7
+ # $ git config --global mergetool.keepBackup false
8
+ *.orig
9
+ .idea
10
+
11
+ # Created by git when using merge tools for conflicts
12
+ *.BACKUP.*
13
+ *.BASE.*
14
+ *.LOCAL.*
15
+ *.REMOTE.*
16
+ *_BACKUP_*.txt
17
+ *_BASE_*.txt
18
+ *_LOCAL_*.txt
19
+ *_REMOTE_*.txt
20
+
21
+ ### Ruby ###
22
+ *.gem
23
+ *.rbc
24
+ /.config
25
+ /coverage/
26
+ /InstalledFiles
27
+ /pkg/
28
+ /spec/reports/
29
+ /spec/examples.txt
30
+ /test/tmp/
31
+ /test/version_tmp/
32
+ /tmp/
33
+
34
+ # Used by dotenv library to load environment variables.
35
+ # .env
36
+
37
+ ## Specific to RubyMotion:
38
+ .dat*
39
+ .repl_history
40
+ build/
41
+ *.bridgesupport
42
+ build-iPhoneOS/
43
+ build-iPhoneSimulator/
44
+
45
+ ## Specific to RubyMotion (use of CocoaPods):
46
+ #
47
+ # We recommend against adding the Pods directory to your .gitignore. However
48
+ # you should judge for yourself, the pros and cons are mentioned at:
49
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
50
+ #
51
+ # vendor/Pods/
52
+
53
+ ## Documentation cache and generated files:
54
+ /.yardoc/
55
+ /_yardoc/
56
+ /doc/
57
+ /rdoc/
58
+
59
+ ## Environment normalization:
60
+ /.bundle/
61
+ /vendor/bundle
62
+ /lib/bundler/man/
63
+
64
+ # for a library or gem, you might want to ignore these files since the code is
65
+ # intended to run in multiple environments; otherwise, check them in:
66
+ # Gemfile.lock
67
+ # .ruby-version
68
+ # .ruby-gemset
69
+
70
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
71
+ .rvmrc
72
+
73
+ ### Vim ###
74
+ # Swap
75
+ [._]*.s[a-v][a-z]
76
+ [._]*.sw[a-p]
77
+ [._]s[a-rt-v][a-z]
78
+ [._]ss[a-gi-z]
79
+ [._]sw[a-p]
80
+
81
+ # Session
82
+ Session.vim
83
+
84
+ # Temporary
85
+ .netrwhist
86
+ *~
87
+ # Auto-generated tag files
88
+ tags
89
+ # Persistent undo
90
+ [._]*.un~
91
+
92
+ # End of https://www.gitignore.io/api/git,vim,ruby
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rainbow', '~> 3.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,13 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ rainbow (3.0.0)
5
+
6
+ PLATFORMS
7
+ ruby
8
+
9
+ DEPENDENCIES
10
+ rainbow (= 3.0.0)
11
+
12
+ BUNDLED WITH
13
+ 1.16.3
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Colorized Grep
2
+ > Minor tool to colorize terminal output
3
+
4
+ ## How
5
+
6
+ ![demo](demo.gif)
7
+
8
+ ```
9
+ ~/path/to/project$ ruby ./cgrep.rb -p beatifull:pink this is the start of a beautiful friendship
10
+ this is the start of a beautiful friendship <-- believe me this will be in pink
11
+ ```
12
+ * -p or --pattern, using the format **pattern:color** to colorize the string match
13
+
14
+ ## Roadmap
15
+
16
+ * create a gem
17
+ * improve README with images/gifs
18
+
19
+ ## Meta
20
+
21
+ Alex Rocha - [about.me](http://about.me/alex.rochas)
data/cgrep.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "cgrep"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Alex Rocha"]
9
+ spec.email = ["alex.rochas@yahoo.com.br"]
10
+
11
+ spec.summary = "Colorized grep"
12
+ spec.description = "To grep and color input by pattern"
13
+ spec.homepage = "https://github.com/alexrochas/colorized-grep"
14
+ spec.license = "MIT"
15
+
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f|
18
+ puts f
19
+ File.basename(f) }
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_dependency "rainbow", "~> 3.0"
26
+ end
data/demo-stdinput.gif ADDED
Binary file
data/demo.gif ADDED
Binary file
data/exe/cgrep ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cgrep"
data/lib/cgrep.rb ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rainbow'
3
+ require 'optparse'
4
+
5
+ @options = {}
6
+ OptionParser.new do |opts|
7
+ opts.banner = "Usage: --pattern PATTERN:COLOR [text]"
8
+
9
+ opts.on("-p", "--pattern PATTERN:COLOR", "Pattern and respective color") do |p|
10
+ @options[:patterns] ||= Array.new
11
+ key, value = p.split(':')
12
+ @options[:patterns] << {key => value}
13
+ end
14
+
15
+ opts.on("-i", "--input", "Standard input") do |i|
16
+ @options[:stdInput] = i
17
+ end
18
+ end.parse!
19
+
20
+ def colorize userInput
21
+ expecs = @options[:patterns]
22
+
23
+ _return = []
24
+
25
+ expecs.each do |expec|
26
+ pattern, color = expec.to_a.first
27
+ if match = userInput.match(Regexp.new(pattern))
28
+ userInput.gsub! match.to_s, Rainbow(match).send(color)
29
+ end
30
+ end
31
+
32
+ userInput
33
+ end
34
+
35
+ if @options[:stdInput]
36
+ while line = $stdin.gets
37
+ puts colorize(line)
38
+ end
39
+ else
40
+ puts colorize(ARGV.join(' '))
41
+ end
42
+
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cgrep
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Rocha
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rainbow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: To grep and color input by pattern
56
+ email:
57
+ - alex.rochas@yahoo.com.br
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
66
+ - cgrep.gemspec
67
+ - demo-stdinput.gif
68
+ - demo.gif
69
+ - exe/cgrep
70
+ - lib/cgrep.rb
71
+ homepage: https://github.com/alexrochas/colorized-grep
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.6.11
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Colorized grep
95
+ test_files: []