grepfruit 1.1.2 → 2.0.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +15 -7
- data/exe/grepfruit +4 -16
- data/grepfruit.gemspec +1 -1
- data/lib/grepfruit/version.rb +1 -1
- data/lib/search.rb +3 -5
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e88618b796ae6c0d9f54ec4bc64033e44ecee9fef5a3a889a0585dff11741e4
|
4
|
+
data.tar.gz: 1d6acc4c77b5175b9d13b3c4eb23b8ed069caf6f8e031037a1ec0244d945fa5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1690b2abec8f59847eace9a70cbaa9d8b08c54d64e35b76ef5d8f2ce6c707478a044e40fad514932f2bbcd9ec2cd289129e05b47497b102ab83fa6ed78dd631b
|
7
|
+
data.tar.gz: 322537a62dbb5d81731af9d973f8b5e69dc557e0721cfabbd8add2da69712b88a231371d5842b2e710fa882b7d03c9e7fd3ed9dfc4a3a5422c893ce0b9f21050
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
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.
|
7
7
|
|
8
|
-
<img width="
|
8
|
+
<img width="440" alt="Screenshot 2024-08-16 at 21 17 25" src="https://github.com/user-attachments/assets/3caaa1f4-5636-4ca1-ae45-6fc56f8945e4">
|
9
9
|
|
10
10
|
Grepfruit was originally created to be used in CI/CD pipelines to search for `TODO` comments in Ruby on Rails applications and provide more user-friendly output than the standard `grep` command, but it is flexible enough to be used for other similar purposes as well.
|
11
11
|
|
@@ -23,14 +23,22 @@ And then execute:
|
|
23
23
|
bundle install
|
24
24
|
```
|
25
25
|
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
```shell
|
29
|
+
gem install grepfruit
|
30
|
+
```
|
31
|
+
|
26
32
|
## Usage
|
27
33
|
|
28
34
|
You can use Grepfruit from the command line to search for a regex pattern within files in a specified directory.
|
29
35
|
|
30
36
|
```shell
|
31
|
-
|
37
|
+
grepfruit [options] PATH
|
32
38
|
```
|
33
39
|
|
40
|
+
If no matches are found, Grepfruit returns exit status 0; otherwise, it returns exit status 1.
|
41
|
+
|
34
42
|
### Options
|
35
43
|
|
36
44
|
- `-r, --regex REGEX`: Regex pattern to search for (required).
|
@@ -43,31 +51,31 @@ bundle exec grepfruit [options] PATH
|
|
43
51
|
Search for the pattern `/TODO/` in the current directory, excluding `log`, `tmp`, `vendor`, `node_modules`, and `assets` directories:
|
44
52
|
|
45
53
|
```shell
|
46
|
-
|
54
|
+
grepfruit -r 'TODO' -e 'log,tmp,vendor,node_modules,assets'
|
47
55
|
```
|
48
56
|
|
49
57
|
Search for the pattern `/FIXME|TODO/` in `dev/grepfruit` directory, excluding `bin`, `tmp/log`, and `Gemfile.lock` files and directories:
|
50
58
|
|
51
59
|
```shell
|
52
|
-
|
60
|
+
grepfruit -r 'FIXME|TODO' -e 'bin,tmp/log,Gemfile.lock' dev/grepfruit
|
53
61
|
```
|
54
62
|
|
55
63
|
Search for the pattern `/FIXME|TODO/` in the current directory, excluding line 18 of `README.md`:
|
56
64
|
|
57
65
|
```shell
|
58
|
-
|
66
|
+
grepfruit -r 'FIXME|TODO' -e 'README.md:18'
|
59
67
|
```
|
60
68
|
|
61
69
|
Search for the pattern `/FIXME|TODO/` in the current directory, truncating the output of the search results to 50 characters:
|
62
70
|
|
63
71
|
```shell
|
64
|
-
|
72
|
+
grepfruit -r 'FIXME|TODO' -t 50
|
65
73
|
```
|
66
74
|
|
67
75
|
Search for the pattern `/FIXME|TODO/` in the current directory, including hidden files and directories:
|
68
76
|
|
69
77
|
```shell
|
70
|
-
|
78
|
+
grepfruit -r 'FIXME|TODO' --search-hidden
|
71
79
|
```
|
72
80
|
|
73
81
|
## Problems?
|
data/exe/grepfruit
CHANGED
@@ -15,22 +15,10 @@ options = {
|
|
15
15
|
|
16
16
|
OptionParser.new do |opts|
|
17
17
|
opts.banner = "Usage: grepfruit [options] PATH"
|
18
|
-
|
19
|
-
opts.on("-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
opts.on("-e", "--exclude x,y,z", Array, "Comma-separated list of files and directories to exclude") do |exclude|
|
24
|
-
options[:exclude] = exclude
|
25
|
-
end
|
26
|
-
|
27
|
-
opts.on("-t", "--truncate N", Integer, "Truncate output to N characters") do |truncate|
|
28
|
-
options[:truncate] = truncate
|
29
|
-
end
|
30
|
-
|
31
|
-
opts.on("--search-hidden", TrueClass, "Search hidden files and directories") do |search_hidden|
|
32
|
-
options[:search_hidden] = search_hidden
|
33
|
-
end
|
18
|
+
opts.on("-r", "--regex REGEX", Regexp, "Regex pattern to search for") { options[:regex] = _1 }
|
19
|
+
opts.on("-e", "--exclude x,y,z", Array, "Comma-separated list of files and directories to exclude") { options[:exclude] = _1 }
|
20
|
+
opts.on("-t", "--truncate N", Integer, "Truncate output to N characters") { options[:truncate] = _1 }
|
21
|
+
opts.on("--search-hidden", TrueClass, "Search hidden files and directories") { options[:search_hidden] = _1 }
|
34
22
|
end.parse!
|
35
23
|
|
36
24
|
if options[:regex].nil?
|
data/grepfruit.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.metadata["rubygems_mfa_required"] = "true"
|
12
12
|
spec.summary = "A Ruby gem for searching text patterns in files with colorized output"
|
13
13
|
spec.license = "MIT"
|
14
|
-
spec.required_ruby_version = ">= 3.
|
14
|
+
spec.required_ruby_version = ">= 3.1", "< 3.5"
|
15
15
|
|
16
16
|
spec.files = [
|
17
17
|
"grepfruit.gemspec", "README.md", "CHANGELOG.md", "LICENSE.txt"
|
data/lib/grepfruit/version.rb
CHANGED
data/lib/search.rb
CHANGED
@@ -13,7 +13,7 @@ module Grepfruit
|
|
13
13
|
def initialize(dir:, regex:, exclude:, truncate:, search_hidden:)
|
14
14
|
@dir = dir
|
15
15
|
@regex = regex
|
16
|
-
@excluded_lines, @excluded_paths = exclude.map {
|
16
|
+
@excluded_lines, @excluded_paths = exclude.map { _1.split("/") }.partition { _1.last.include?(":") }
|
17
17
|
@truncate = truncate
|
18
18
|
@search_hidden = search_hidden
|
19
19
|
end
|
@@ -35,9 +35,7 @@ module Grepfruit
|
|
35
35
|
File.foreach(path).with_index do |line, line_num|
|
36
36
|
next unless line.valid_encoding?
|
37
37
|
|
38
|
-
if line.match?(regex)
|
39
|
-
next if excluded_line?(path, line_num)
|
40
|
-
|
38
|
+
if line.match?(regex) && !excluded_line?(path, line_num)
|
41
39
|
lines << "#{CYAN}#{relative_path_with_line_num(path, line_num)}#{RESET}: #{processed_line(line)}"
|
42
40
|
match = true
|
43
41
|
end
|
@@ -70,7 +68,7 @@ module Grepfruit
|
|
70
68
|
end
|
71
69
|
|
72
70
|
def excluded?(list, path)
|
73
|
-
list.any? {
|
71
|
+
list.any? { path.split("/").last(_1.length) == _1 }
|
74
72
|
end
|
75
73
|
|
76
74
|
def relative_path(path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grepfruit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- enjaku4
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -41,17 +41,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: '3.
|
44
|
+
version: '3.1'
|
45
45
|
- - "<"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.5'
|
48
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '0'
|
53
53
|
requirements: []
|
54
|
-
rubygems_version: 3.
|
54
|
+
rubygems_version: 3.3.27
|
55
55
|
signing_key:
|
56
56
|
specification_version: 4
|
57
57
|
summary: A Ruby gem for searching text patterns in files with colorized output
|