grepfruit 1.0.0 → 1.1.1

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: 793a10b4b4676491d13d45fd598316ce327cfa660962ce37c7e3404a383f1a2e
4
- data.tar.gz: 84f8ab7c8ff9350c95182dcc1127e7ec779b8f5a0f0f9567d845680275bda9c3
3
+ metadata.gz: 32c9440099c6773c0462e07588d75db0dbc068417e01f1d9a1449dcdc2ee1031
4
+ data.tar.gz: 6ee33ae41606b4ee5d65204e6a9ae0c7d162d0b3fe6a30bac230aec272e91940
5
5
  SHA512:
6
- metadata.gz: d9a329e3105b5ab178180fb415ca72af96c62ab91a47d18669a3ac8514f25a5380e0d5840f457863b3f00b76766d7ddba3ca53951cfa8010e86525bca445ed41
7
- data.tar.gz: d94287b1c4f5954920853f9303586803fb918877c7f18146528add86457b53940a4cfcda47ca63794b8caf002a7b6d02b0b3e19b6c39d5b03d5bad32b1d7e8a8
6
+ metadata.gz: be872e34b8520febbadefc4ab7a747f7bdf0bc4f59fc4a7b09902d6eb3b1caba434820b6745c0086dacde3d82c21c21c0722f3e7b492a014c08311586188b865
7
+ data.tar.gz: 10c7be4bc77fa12b3f7da587ac921073424af09df6534d4df4929f8d24402a76daf349fd2ded696be121469dbea1fb1fad7323ba11559809dfa3aa87d5827286
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## v1.1.1
2
+
3
+ - Added test dataset to make testing and development easier
4
+ - Updated gemspec file to include missing metadata
5
+
6
+ ## v1.1.0
7
+
8
+ - Added `--truncate` option to truncate the output of the search results
9
+ - Added the ability to exclude lines from the search results
10
+
1
11
  ## v1.0.0
2
12
 
3
13
  - Removed default values for `--exclude` and `--regex` options
data/README.md CHANGED
@@ -33,8 +33,9 @@ bundle exec grepfruit [options] PATH
33
33
 
34
34
  ### Options
35
35
 
36
- - `-r, --regex REGEX`: Regex pattern to search for (required).
37
- - `-e, --exclude x,y,z`: Comma-separated list of files and directories to exclude from the search.
36
+ - `-r, --regex REGEX`: Regex pattern to search for (required).
37
+ - `-e, --exclude x,y,z`: Comma-separated list of files, directories, or lines to exclude from the search.
38
+ - `-t, --truncate N`: Truncate the output of the search results to N characters.
38
39
  - `--search-hidden`: Search hidden files and directories.
39
40
 
40
41
  ### Examples
@@ -43,8 +44,6 @@ Search for the pattern `/TODO/` in the current directory, excluding `log`, `tmp`
43
44
 
44
45
  ```shell
45
46
  bundle exec grepfruit -r 'TODO' -e 'log,tmp,vendor,node_modules,assets'
46
- # or
47
- bundle exec grepfruit --regex 'TODO' --exclude 'log,tmp,vendor,node_modules,assets'
48
47
  ```
49
48
 
50
49
  Search for the pattern `/FIXME|TODO/` in `dev/grepfruit` directory, excluding `bin`, `tmp/log`, and `Gemfile.lock` files and directories:
@@ -53,6 +52,18 @@ Search for the pattern `/FIXME|TODO/` in `dev/grepfruit` directory, excluding `b
53
52
  bundle exec grepfruit -r 'FIXME|TODO' -e 'bin,tmp/log,Gemfile.lock' dev/grepfruit
54
53
  ```
55
54
 
55
+ Search for the pattern `/FIXME|TODO/` in the current directory, excluding line 18 of `README.md`:
56
+
57
+ ```shell
58
+ bundle exec grepfruit -r 'FIXME|TODO' -e 'README.md:18'
59
+ ```
60
+
61
+ Search for the pattern `/FIXME|TODO/` in the current directory, truncating the output of the search results to 50 characters:
62
+
63
+ ```shell
64
+ bundle exec grepfruit -r 'FIXME|TODO' -t 50
65
+ ```
66
+
56
67
  Search for the pattern `/FIXME|TODO/` in the current directory, including hidden files and directories:
57
68
 
58
69
  ```shell
data/exe/grepfruit CHANGED
@@ -6,9 +6,10 @@ require "optparse"
6
6
  require "grepfruit"
7
7
 
8
8
  options = {
9
- path: Dir.pwd,
9
+ dir: Dir.pwd,
10
10
  regex: nil,
11
11
  exclude: [],
12
+ truncate: nil,
12
13
  search_hidden: false
13
14
  }
14
15
 
@@ -20,7 +21,11 @@ OptionParser.new do |opts|
20
21
  end
21
22
 
22
23
  opts.on("-e", "--exclude x,y,z", Array, "Comma-separated list of files and directories to exclude") do |exclude|
23
- options[:exclude] = exclude.map! { |path| path.split("/") }
24
+ options[:exclude] = exclude.map { |path| path.split("/") }
25
+ end
26
+
27
+ opts.on("-t", "--truncate N", Integer, "Truncate output to N characters") do |truncate|
28
+ options[:truncate] = truncate
24
29
  end
25
30
 
26
31
  opts.on("--search-hidden", TrueClass, "Search hidden files and directories") do |search_hidden|
@@ -33,6 +38,6 @@ if options[:regex].nil?
33
38
  exit 1
34
39
  end
35
40
 
36
- options[:path] = ARGV[0] if ARGV[0]
41
+ options[:dir] = ARGV[0] if ARGV[0]
37
42
 
38
43
  Grepfruit.run(**options)
data/grepfruit.gemspec CHANGED
@@ -4,11 +4,14 @@ Gem::Specification.new do |spec|
4
4
  spec.name = "grepfruit"
5
5
  spec.version = Grepfruit::VERSION
6
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
7
  spec.homepage = "https://github.com/enjaku4/grepfruit"
8
+ spec.metadata["homepage_uri"] = spec.homepage
9
+ spec.metadata["source_code_uri"] = spec.homepage
10
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
11
+ spec.metadata["rubygems_mfa_required"] = "true"
12
+ spec.summary = "A Ruby gem for searching text patterns in files with colorized output"
10
13
  spec.license = "MIT"
11
- spec.required_ruby_version = ">= 3.0.0", "< 3.4"
14
+ spec.required_ruby_version = ">= 3.0", "< 3.4"
12
15
 
13
16
  spec.files = [
14
17
  "grepfruit.gemspec", "README.md", "CHANGELOG.md", "LICENSE.txt"
@@ -1,3 +1,3 @@
1
1
  module Grepfruit
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.1"
3
3
  end
data/lib/grepfruit.rb CHANGED
@@ -3,27 +3,34 @@ require "pathname"
3
3
  require "find"
4
4
 
5
5
  module Grepfruit
6
- def self.run(path:, regex:, exclude:, search_hidden:)
6
+ def self.run(dir:, regex:, exclude:, truncate:, search_hidden:)
7
7
  lines = []
8
8
  files = 0
9
- dir = path
9
+ excluded_lines = exclude.select { |e| e.any? { |s| s.include?(":") } }
10
+ excluded_paths = exclude - excluded_lines
10
11
 
11
- puts "Searching for #{regex.inspect}...\n\n"
12
+ puts "Searching for #{regex.inspect} in #{dir.inspect}...\n\n"
12
13
 
13
- Find.find(dir) do |pth|
14
- Find.prune if exclude.any? { |e| pth.split("/").last(e.length) == e } || !search_hidden && File.basename(pth).start_with?(".")
14
+ Find.find(dir) do |path|
15
+ Find.prune if excluded_paths.any? { |e| path.split("/").last(e.length) == e } || !search_hidden && File.basename(path).start_with?(".")
15
16
 
16
- next if File.directory?(pth) || File.symlink?(pth)
17
+ next if File.directory?(path) || File.symlink?(path)
17
18
 
18
19
  files += 1
19
20
 
20
21
  match = false
21
22
 
22
- File.foreach(pth).with_index do |line, line_num|
23
+ File.foreach(path).with_index do |line, line_num|
23
24
  next unless line.valid_encoding?
24
25
 
25
26
  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
+ path_with_line = "#{Pathname.new(path).relative_path_from(Pathname.new(dir))}:#{line_num + 1}"
28
+
29
+ next if excluded_lines.any? { |e| path_with_line.split("/").last(e.length) == e }
30
+
31
+ processed_line = line.strip
32
+ processed_line = "#{processed_line[0..truncate - 1]}..." if truncate && processed_line.length > truncate
33
+ lines << "\e[36m#{path_with_line}\e[0m: #{processed_line}"
27
34
  match = true
28
35
  end
29
36
  end
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: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - enjaku4
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-30 00:00:00.000000000 Z
11
+ date: 2024-08-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -28,6 +28,9 @@ homepage: https://github.com/enjaku4/grepfruit
28
28
  licenses:
29
29
  - MIT
30
30
  metadata:
31
+ homepage_uri: https://github.com/enjaku4/grepfruit
32
+ source_code_uri: https://github.com/enjaku4/grepfruit
33
+ changelog_uri: https://github.com/enjaku4/grepfruit/blob/master/CHANGELOG.md
31
34
  rubygems_mfa_required: 'true'
32
35
  post_install_message:
33
36
  rdoc_options: []
@@ -37,7 +40,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - ">="
39
42
  - !ruby/object:Gem::Version
40
- version: 3.0.0
43
+ version: '3.0'
41
44
  - - "<"
42
45
  - !ruby/object:Gem::Version
43
46
  version: '3.4'
@@ -47,8 +50,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
50
  - !ruby/object:Gem::Version
48
51
  version: '0'
49
52
  requirements: []
50
- rubygems_version: 3.5.11
53
+ rubygems_version: 3.2.33
51
54
  signing_key:
52
55
  specification_version: 4
53
- summary: A tool for searching text patterns in files with colorized output.
56
+ summary: A Ruby gem for searching text patterns in files with colorized output
54
57
  test_files: []