grepfruit 0.1.0 → 0.2.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 +4 -0
- data/README.md +15 -5
- data/exe/grepfruit +8 -3
- data/lib/grepfruit/version.rb +1 -1
- data/lib/grepfruit.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '028c0f4cdd37b9257eb272c1dd961629c26da09a4353d7bafa42eb81314c14d1'
|
4
|
+
data.tar.gz: 282d0e315b69db474eed1b27b1a7cd9b5cb693057c4125b81f4883db27c262d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e821650c6ff4777eff717d26a0d481928bb91bfa93af7336e359023f2fc7ccfddb6ae4bdc724ecd81c0d1a3799420605f6c66e09c756fbbf87ea5b64ba30527
|
7
|
+
data.tar.gz: 8dacf807b6da4d56b1e7dfdc68dca009eb98f9b83b876e18415bab0803d52292cc19688081a2526cdeab1e041eddbb5025dc0b27d0093f340b4b72ea1754cf96
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Grepfruit
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/grepfruit)
|
4
|
+
[](https://github.com/enjaku4/grepfruit/actions/workflows/main.yml)
|
5
|
+
|
3
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.
|
4
7
|
|
5
8
|
<img width="416" alt="Screenshot 2024-07-28 at 03 52 37" src="https://github.com/user-attachments/assets/95b26b81-dcc1-430b-ac44-641251cb84b6">
|
@@ -23,26 +26,33 @@ bundle install
|
|
23
26
|
You can use Grepfruit from the command line to search for a regex pattern within files in a specified directory.
|
24
27
|
|
25
28
|
```shell
|
26
|
-
grepfruit [options] PATH
|
29
|
+
bundle exec grepfruit [options] PATH
|
27
30
|
```
|
28
31
|
|
29
32
|
### Options
|
30
33
|
|
31
|
-
- `-r, --regex REGEX
|
32
|
-
- `-e, --exclude x,y,z
|
34
|
+
- `-r, --regex REGEX`: Regex pattern to search for. Defaults to /TODO/.
|
35
|
+
- `-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.
|
36
|
+
- `--search-hidden`: Search hidden files and directories. Defaults to false.
|
33
37
|
|
34
38
|
### Examples
|
35
39
|
|
36
40
|
Search for the pattern `TODO` in the current directory, excluding the default directories:
|
37
41
|
|
38
42
|
```shell
|
39
|
-
grepfruit
|
43
|
+
bundle exec grepfruit
|
40
44
|
```
|
41
45
|
|
42
46
|
Search for a custom pattern in another directory, while specifying files and directories to exclude:
|
43
47
|
|
44
48
|
```shell
|
45
|
-
grepfruit -r 'FIXME|TODO' -e '
|
49
|
+
bundle exec grepfruit -r 'FIXME|TODO' -e 'log,Gemfile.lock,foo/bar.baz' /path/to/directory
|
50
|
+
```
|
51
|
+
|
52
|
+
Search for a pattern in the current directory, including hidden files and directories:
|
53
|
+
|
54
|
+
```shell
|
55
|
+
bundle exec grepfruit -r 'FIXME|TODO' --search-hidden
|
46
56
|
```
|
47
57
|
|
48
58
|
## Problems?
|
data/exe/grepfruit
CHANGED
@@ -8,19 +8,24 @@ require "grepfruit"
|
|
8
8
|
options = {
|
9
9
|
path: Dir.pwd,
|
10
10
|
regex: /TODO/,
|
11
|
-
exclude: [["log"], ["tmp"], ["vendor"], ["node_modules"], ["assets"]]
|
11
|
+
exclude: [["log"], ["tmp"], ["vendor"], ["node_modules"], ["assets"]],
|
12
|
+
search_hidden: false
|
12
13
|
}
|
13
14
|
|
14
15
|
OptionParser.new do |opts|
|
15
16
|
opts.banner = "Usage: grepfruit [options] PATH"
|
16
17
|
|
17
|
-
opts.on("-r", "--regex REGEX", "Regex pattern to search for") do |regex|
|
18
|
-
options[:regex] =
|
18
|
+
opts.on("-r", "--regex REGEX", Regexp, "Regex pattern to search for") do |regex|
|
19
|
+
options[:regex] = regex
|
19
20
|
end
|
20
21
|
|
21
22
|
opts.on("-e", "--exclude x,y,z", Array, "Comma-separated list of files and directories to exclude") do |exclude|
|
22
23
|
options[:exclude] = exclude.map! { |path| path.split("/") }
|
23
24
|
end
|
25
|
+
|
26
|
+
opts.on("--search-hidden", TrueClass, "Search hidden files and directories") do |search_hidden|
|
27
|
+
options[:search_hidden] = search_hidden
|
28
|
+
end
|
24
29
|
end.parse!
|
25
30
|
|
26
31
|
options[:path] = ARGV[0] if ARGV[0]
|
data/lib/grepfruit/version.rb
CHANGED
data/lib/grepfruit.rb
CHANGED
@@ -3,7 +3,7 @@ require "pathname"
|
|
3
3
|
require "find"
|
4
4
|
|
5
5
|
module Grepfruit
|
6
|
-
def self.run(path:, regex:, exclude:)
|
6
|
+
def self.run(path:, regex:, exclude:, search_hidden:)
|
7
7
|
lines = []
|
8
8
|
files = 0
|
9
9
|
dir = path
|
@@ -11,7 +11,7 @@ module Grepfruit
|
|
11
11
|
puts "Searching for #{regex.inspect}...\n\n"
|
12
12
|
|
13
13
|
Find.find(dir) do |pth|
|
14
|
-
Find.prune if exclude.any? { |e| pth.split("/").last(e.length) == e } || File.basename(pth).start_with?(".")
|
14
|
+
Find.prune if exclude.any? { |e| pth.split("/").last(e.length) == e } || !search_hidden && File.basename(pth).start_with?(".")
|
15
15
|
|
16
16
|
next if File.directory?(pth)
|
17
17
|
|