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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64111f942b9dd8e2b1b6957b552e582fc9b7870225dd40e8042de30e06832dca
4
- data.tar.gz: 40c9d6fe5cd104aa4deca5c0eadd0299851bcd286b086fd50da2ed02bbf385af
3
+ metadata.gz: '028c0f4cdd37b9257eb272c1dd961629c26da09a4353d7bafa42eb81314c14d1'
4
+ data.tar.gz: 282d0e315b69db474eed1b27b1a7cd9b5cb693057c4125b81f4883db27c262d9
5
5
  SHA512:
6
- metadata.gz: 0bf856a22a4ab91c636e7b9ab9ae03f947b5344c9fa3266617aa4c8812e7ffd0228a84a88fa0fad9bcd10479b7b40258c85a213a160eb6d740d615111f7fbc04
7
- data.tar.gz: 6901c591fc559557064034ffce12a79c7d3f6ca8972bb00134429bed51dfab404fcc93b13b350d10acf1a281c54fe844cbbcf54a337ddb706e5dcf8af4883067
6
+ metadata.gz: 6e821650c6ff4777eff717d26a0d481928bb91bfa93af7336e359023f2fc7ccfddb6ae4bdc724ecd81c0d1a3799420605f6c66e09c756fbbf87ea5b64ba30527
7
+ data.tar.gz: 8dacf807b6da4d56b1e7dfdc68dca009eb98f9b83b876e18415bab0803d52292cc19688081a2526cdeab1e041eddbb5025dc0b27d0093f340b4b72ea1754cf96
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.2.0
2
+
3
+ - Added `--search-hidden` option to search hidden files and directories
4
+
1
5
  ## v0.1.0
2
6
 
3
7
  - Initial release
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Grepfruit
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/grepfruit.svg)](http://badge.fury.io/rb/grepfruit)
4
+ [![Github Actions badge](https://github.com/enjaku4/grepfruit/actions/workflows/main.yml/badge.svg)](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: 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.
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 'bin,log,Rakefile,Gemfile.lock' /path/to/directory
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] = /#{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]
@@ -1,3 +1,3 @@
1
1
  module Grepfruit
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grepfruit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - enjaku4