grepfruit 0.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 +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +69 -0
- data/exe/grepfruit +28 -0
- data/grepfruit.gemspec +20 -0
- data/lib/grepfruit/version.rb +3 -0
- data/lib/grepfruit.rb +46 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 64111f942b9dd8e2b1b6957b552e582fc9b7870225dd40e8042de30e06832dca
|
4
|
+
data.tar.gz: 40c9d6fe5cd104aa4deca5c0eadd0299851bcd286b086fd50da2ed02bbf385af
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0bf856a22a4ab91c636e7b9ab9ae03f947b5344c9fa3266617aa4c8812e7ffd0228a84a88fa0fad9bcd10479b7b40258c85a213a160eb6d740d615111f7fbc04
|
7
|
+
data.tar.gz: 6901c591fc559557064034ffce12a79c7d3f6ca8972bb00134429bed51dfab404fcc93b13b350d10acf1a281c54fe844cbbcf54a337ddb706e5dcf8af4883067
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 enjaku4 (https://github.com/enjaku4)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Grepfruit
|
2
|
+
|
3
|
+
Grepfruit is a Ruby gem for searching files within a directory for a specified regular expression pattern, with options to exclude certain files or directories from the search and colorized output for better readability.
|
4
|
+
|
5
|
+
<img width="416" alt="Screenshot 2024-07-28 at 03 52 37" src="https://github.com/user-attachments/assets/95b26b81-dcc1-430b-ac44-641251cb84b6">
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'grepfruit'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```shell
|
18
|
+
bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
You can use Grepfruit from the command line to search for a regex pattern within files in a specified directory.
|
24
|
+
|
25
|
+
```shell
|
26
|
+
grepfruit [options] PATH
|
27
|
+
```
|
28
|
+
|
29
|
+
### Options
|
30
|
+
|
31
|
+
- `-r, --regex REGEX: Regex pattern to search for. Defaults to /TODO/.
|
32
|
+
- `-e, --exclude x,y,z: Comma-separated list of files and directories to exclude from the search. Defaults to log, tmp, vendor, node_modules, assets.
|
33
|
+
|
34
|
+
### Examples
|
35
|
+
|
36
|
+
Search for the pattern `TODO` in the current directory, excluding the default directories:
|
37
|
+
|
38
|
+
```shell
|
39
|
+
grepfruit
|
40
|
+
```
|
41
|
+
|
42
|
+
Search for a custom pattern in another directory, while specifying files and directories to exclude:
|
43
|
+
|
44
|
+
```shell
|
45
|
+
grepfruit -r 'FIXME|TODO' -e 'bin,log,Rakefile,Gemfile.lock' /path/to/directory
|
46
|
+
```
|
47
|
+
|
48
|
+
## Problems?
|
49
|
+
|
50
|
+
Facing a problem or want to suggest an enhancement?
|
51
|
+
|
52
|
+
- **Open a Discussion**: If you have a question, experience difficulties using the gem, or have a suggestion for improvements, feel free to use the Discussions section.
|
53
|
+
|
54
|
+
Encountered a bug?
|
55
|
+
|
56
|
+
- **Create an Issue**: If you've identified a bug, please create an issue. Be sure to provide detailed information about the problem, including the steps to reproduce it.
|
57
|
+
- **Contribute a Solution**: Found a fix for the issue? Feel free to create a pull request with your changes.
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Before creating an issue or a pull request, please read the [contributing guidelines](https://github.com/enjaku4/grepfruit/blob/master/CONTRIBUTING.md).
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
The gem is available as open source under the terms of the [MIT License](https://github.com/enjaku4/grepfruit/blob/master/LICENSE.txt).
|
66
|
+
|
67
|
+
## Code of Conduct
|
68
|
+
|
69
|
+
Everyone interacting in the Grepfruit project is expected to follow the [code of conduct](https://github.com/enjaku4/grepfruit/blob/master/CODE_OF_CONDUCT.md).
|
data/exe/grepfruit
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift("#{__dir__}/../lib")
|
4
|
+
|
5
|
+
require "optparse"
|
6
|
+
require "grepfruit"
|
7
|
+
|
8
|
+
options = {
|
9
|
+
path: Dir.pwd,
|
10
|
+
regex: /TODO/,
|
11
|
+
exclude: [["log"], ["tmp"], ["vendor"], ["node_modules"], ["assets"]]
|
12
|
+
}
|
13
|
+
|
14
|
+
OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: grepfruit [options] PATH"
|
16
|
+
|
17
|
+
opts.on("-r", "--regex REGEX", "Regex pattern to search for") do |regex|
|
18
|
+
options[:regex] = /#{regex}/
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-e", "--exclude x,y,z", Array, "Comma-separated list of files and directories to exclude") do |exclude|
|
22
|
+
options[:exclude] = exclude.map! { |path| path.split("/") }
|
23
|
+
end
|
24
|
+
end.parse!
|
25
|
+
|
26
|
+
options[:path] = ARGV[0] if ARGV[0]
|
27
|
+
|
28
|
+
Grepfruit.run(**options)
|
data/grepfruit.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "lib/grepfruit/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "grepfruit"
|
5
|
+
spec.version = Grepfruit::VERSION
|
6
|
+
spec.authors = ["enjaku4"]
|
7
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
8
|
+
spec.summary = "A tool for searching text patterns in files with colorized output."
|
9
|
+
spec.homepage = "https://github.com/enjaku4/grepfruit"
|
10
|
+
spec.license = "MIT"
|
11
|
+
spec.required_ruby_version = ">= 3.0.0", "< 3.4"
|
12
|
+
|
13
|
+
spec.files = [
|
14
|
+
"grepfruit.gemspec", "README.md", "CHANGELOG.md", "LICENSE.txt"
|
15
|
+
] + `git ls-files | grep -E '^(lib|exe)'`.split("\n")
|
16
|
+
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = ["grepfruit"]
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
end
|
data/lib/grepfruit.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative "grepfruit/version"
|
2
|
+
require "pathname"
|
3
|
+
require "find"
|
4
|
+
|
5
|
+
module Grepfruit
|
6
|
+
def self.run(path:, regex:, exclude:)
|
7
|
+
lines = []
|
8
|
+
files = 0
|
9
|
+
dir = path
|
10
|
+
|
11
|
+
puts "Searching for #{regex.inspect}...\n\n"
|
12
|
+
|
13
|
+
Find.find(dir) do |pth|
|
14
|
+
Find.prune if exclude.any? { |e| pth.split("/").last(e.length) == e } || File.basename(pth).start_with?(".")
|
15
|
+
|
16
|
+
next if File.directory?(pth)
|
17
|
+
|
18
|
+
files += 1
|
19
|
+
|
20
|
+
match = false
|
21
|
+
|
22
|
+
File.foreach(pth).with_index do |line, line_num|
|
23
|
+
next unless line.valid_encoding?
|
24
|
+
|
25
|
+
if line.match?(regex)
|
26
|
+
lines << "\e[36m#{Pathname.new(pth).relative_path_from(Pathname.new(dir))}:#{line_num + 1}\e[0m: #{line.strip}"
|
27
|
+
match = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
print match ? "\e[31mF\e[0m" : "\e[32m.\e[0m"
|
32
|
+
end
|
33
|
+
|
34
|
+
puts "\n\n"
|
35
|
+
|
36
|
+
if lines.empty?
|
37
|
+
puts "#{files} files checked, \e[32mno matches found\e[0m"
|
38
|
+
exit(0)
|
39
|
+
else
|
40
|
+
puts "Matches:\n\n"
|
41
|
+
puts "#{lines.join("\n")}\n\n"
|
42
|
+
puts "#{files} file#{'s' if files > 1} checked, \e[31m#{lines.size} match#{'es' if lines.size > 1} found\e[0m"
|
43
|
+
exit(1)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grepfruit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- enjaku4
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables:
|
16
|
+
- grepfruit
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- CHANGELOG.md
|
21
|
+
- LICENSE.txt
|
22
|
+
- README.md
|
23
|
+
- exe/grepfruit
|
24
|
+
- grepfruit.gemspec
|
25
|
+
- lib/grepfruit.rb
|
26
|
+
- lib/grepfruit/version.rb
|
27
|
+
homepage: https://github.com/enjaku4/grepfruit
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata:
|
31
|
+
rubygems_mfa_required: 'true'
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
41
|
+
- - "<"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.4'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubygems_version: 3.2.33
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: A tool for searching text patterns in files with colorized output.
|
54
|
+
test_files: []
|