rbfind 2.13 → 2.14

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: 98488c856ff5755a635ef73c4c25fa7dfba6f84dbe4ee41546ffb22e4ec82fb1
4
- data.tar.gz: f48565d71eedeef67f1cc93008c185df4637f26ba2ca1d409dc0887b44ff48e0
3
+ metadata.gz: d2f219a0e17b31db93bb38ec0425b37cc0a5921cdbd89638bab4de5d4303e161
4
+ data.tar.gz: 0d470ef4ceac6aa088aea20c4ae7804341fbb5a84d23108bf5342acb6ad5e0e7
5
5
  SHA512:
6
- metadata.gz: ee7b581d587bb0730b2aad2a502bc7ef3ce54a1bfe5742ca4bc92995aaba06db6400e30c9d23a2f8ae04c62d0b608cccf2a11cdd64f13bc23ab39f6c6af1e6b9
7
- data.tar.gz: bfdb28913be3435781c52c630fbff63d29965908cafee6494a6c6a267a8da1ce568a71424687d8298f655aa66a5998e74d391934689c2d31fa33f9df364c8dc0
6
+ metadata.gz: d67aae93c618f927f4b3c8ffad8916c0e526be0a59c9567538b90ac5de8d70f317799119347aa370088aae5a77ca95b30eec90f18fd269006d0ec886247f1ecf
7
+ data.tar.gz: 56c9ba35469ac5b677b2aa3c6e7b9ee5977e0abcf65c563704aa768b29fc6afdf92ff92931c317c8a273af69b3ed2344cf25ee6e8d10d9782fb30043b438c956
data/LICENSE CHANGED
@@ -1,24 +1,24 @@
1
- ____ _ _____ _ _
2
- | _ \| |__ | ___(_)_ __ __| |
3
- | |_) | '_ \| |_ | | '_ \ / _` |
4
- | _ <| |_) | _| | | | | | (_| |
5
- |_| \_\_.__/|_| |_|_| |_|\__,_|
1
+ # BSD-2-clause license, extended by language use conditions
6
2
 
7
-
8
- Copyright (c) 2008-2019, Bertram Scharpf <software@bertram-scharpf.de>.
3
+ Copyright (C) 2008-2025, Bertram Scharpf <software@bertram-scharpf.de>.
9
4
  All rights reserved.
10
5
 
11
6
  Redistribution and use in source and binary forms, with or without
12
7
  modification, are permitted provided that the following conditions are
13
8
  met:
14
9
 
15
- * Redistributions of source code must retain the above copyright
16
- notice, this list of conditions and the following disclaimer.
10
+ * Redistributions of source code must retain the above copyright
11
+ notice, this list of conditions and the following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above copyright
14
+ notice, this list of conditions and the following disclaimer in
15
+ the documentation and/or other materials provided with the
16
+ distribution.
17
17
 
18
- * Redistributions in binary form must reproduce the above copyright
19
- notice, this list of conditions and the following disclaimer in
20
- the documentation and/or other materials provided with the
21
- distribution.
18
+ * Redistributions must not contain any clauses about anticipated
19
+ harassment or discrimination, nor must they be held in a so-called
20
+ "inclusive language". As far as German language is used, the
21
+ conditions mentioned below additionally apply.
22
22
 
23
23
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
24
  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -32,3 +32,21 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
32
  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
33
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
34
 
35
+
36
+ ## Use of the German Language
37
+
38
+ Beim Gebrauch deutscher Sprache sind Weiterentwicklungen und
39
+ -verbreitungen nur gestattet unter Einhaltung sowie abermaligen
40
+ Einforderns folgender zusätzlicher Bedingungen:
41
+
42
+ * Keine Verwendung von sogenannter „geschlechtergerechter Sprache“,
43
+ also Anfügen von weiblichen Endungen mit Binnen-I, Sternchen,
44
+ Doppelpunkt, Unterstrich oder ähnlichem, oder Konstruktionen, die
45
+ den Sachverhalt falsch wiedergeben („Radfahrende“, „Studierende“).
46
+
47
+ * Keine Verwendung der „reformierten Rechtschreibung“ von 1996,
48
+ insbesondere Doppel-S am Silbenende, „plazieren“ mit T, sowie
49
+ Großschreibung von Wendungen wie „des weiteren“.
50
+
51
+
52
+ <!-- vim:set ft=markdown : -->
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # RbFind
2
+
3
+ A substitute for the Unix find tool using Ruby expressions
4
+
5
+
6
+ ## Description
7
+
8
+ RbFind does the same as the standard Unix find tool but has a
9
+ different calling syntax. Specify your search reqest as a
10
+ Ruby expression.
11
+
12
+
13
+ ## Features
14
+
15
+ * ls long format style output
16
+ * Built-in grep
17
+ * Colored ls and grep output
18
+ * Automatically exclude version control system or Vim swap files
19
+ * No dependecies
20
+
21
+
22
+ ## Example
23
+
24
+ Find files that were modified in the last five minutes.
25
+
26
+ ```sh
27
+ rbfind -p 'file and age < 5.m'
28
+ ```
29
+
30
+ Grep whole directory but skip `.git/` or `.svn/`, and
31
+ `.filename.swp`.
32
+
33
+ ```sh
34
+ rbfind -CWg require
35
+ ```
36
+
37
+ Save time and do not grep large files.
38
+
39
+ ```sh
40
+ rbfind 'filesize < 100.kB and grep /require/'
41
+ ```
42
+
43
+ Output ls long format.
44
+
45
+ ```sh
46
+ rbfind -P
47
+ ```
48
+
49
+ Print MD5 digest and size for each file.
50
+
51
+ ```sh
52
+ rbfind 'spacesep digest_md5, size.w8, path'
53
+ ```
54
+
55
+
56
+ ## Copyright
57
+
58
+ * (C) 2008-2025, Bertram Scharpf <software@bertram-scharpf.de>
59
+ * License: [BSD-2-Clause+](./LICENSE)
60
+ * Repository: [ruby-nvim](https://github.com/BertramScharpf/rbfind.git)
61
+
data/bin/rbfind CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  #
4
4
  # rbfind -- Ruby Find with many features
@@ -6,13 +6,12 @@
6
6
 
7
7
  require "rbfind"
8
8
  require "rbfind/humansiz"
9
- require "English"
10
- require 'getoptlong'
9
+ require 'rbfind/appl'
11
10
 
12
11
 
13
12
  module RbFind
14
13
 
15
- class Application
14
+ class RbFindAppl < Application
16
15
 
17
16
  PROGRAM = <<~EOT
18
17
  rbfind #{RbFind::VERSION} -- A find tool using Ruby
@@ -21,129 +20,65 @@ module RbFind
21
20
  License: BSD
22
21
  EOT
23
22
 
24
- OPTIONS = [
25
- # options arg description
26
- [ %w(--help -h), nil, "print this help"],
27
- [ %w(--examples -X), nil, "print this help and examples"],
28
- [ %w(--version -V), nil, "print version information"],
29
- [ %w(--verbose -v), nil, "standard Ruby error reports"],
30
- [ %w(--show -o), nil, "just show Ruby block built from options"],
31
- [ %w(--bw -w), nil, "black and white on -p or default output"],
32
- [ %w(--colored -c), nil, "force color on -p or default output"],
33
- [ %w(--depth -d), nil, "yield directory after its contents"],
34
- [ %w(--maxdepth -m), :num, "maxium step depth (0 = any)"],
35
- [ %w(--argsdepth -A), nil, "args have depth 1 (not 0)"],
36
- [ %w(--follow -y), nil, "follow symbolic links"],
37
- [ %w(--nosort -U), nil, "unsorted"],
38
- [ %w(--sort-by -s), :str, "sort expression"],
39
- [ %w(--reverse -R), nil, "reverse the sort"],
40
- [ %w(--time -t), nil, "sort by time, newest first"],
41
- [ %w(--size -S), nil, "sort by size, largest first"],
42
- [ %w(--dirs -F), nil, "sort directories before files"],
43
- [ %w(--require -r), :rb, "require library"],
44
- [ %w(--puts-path -p), nil, "do 'puts path/cpath' on true block"],
45
- [ %w(--ls-l -P), nil, "do 'ls -l' style output on true block"],
46
- [ %w(--long -Q), nil, "alternate long format on true block"],
47
- [ %w(--humanage -H), nil, "long format with human readable ages"],
48
- [ %w(--ino -J), nil, "show inodes and number of hard links"],
49
- [ %w(--wider -+), nil, "widen fields in long output format"],
50
- [ %w(--slash -/), nil, "append a slash to directory names"],
51
- [ %w(--lines -l), :blk, "surround block by 'lines { |$_,$.| ... }'"],
52
- [ %w(--reallines -L), :blk, "same as -l but stop at any null character"],
53
- [ %w(--grep -g), :blk, "grep files (implies -pL)"],
54
- [ %w(--igrep -G), :blk, "case insensitive grep"],
55
- [ %w(--binary -b), nil, "grep even binary files"],
56
- [ %w(--no-vcs -C), nil, "prune version control dirs (CVS/.svn/.git)"],
57
- [ %w(--no-swap -W), nil, "ignore Vim swapfiles"],
58
- [ %w(--skip -k), :rgx, "filenames to skip"],
59
- [ %w(--demand -D), :rgx, "skip all filenames but these"],
60
- [ %w(--ext -e), :lst, "skip all filename extensions but these"],
61
- [ %w(--visible -I), nil, "skip all hidden (starting with .dot)"],
62
- [ %w(--all -a), nil, "all, including hidden (starting with .dot)"],
63
- [ %w(--icase -i), nil, "ignore case in file and path matches"],
64
- [ %w(--nodirs -N), nil, "skip directories"],
65
- [ %w(--begin -B), :blk, "eval block before begin"],
66
- [ %w(--end -E), :blk, "eval block after end"],
67
- [ %w(--file -f), :nam, "read block expression from file"],
68
- [ %w(--encoding -K), :str, "encoding extern[:intern] (same as ruby -E)"],
69
- [ %w(--width-user ), :num, "width of user field"],
70
- [ %w(--width-size ), :num, "width of size field"],
71
- ]
72
-
73
- def initialize
23
+ option %w(h help ), "print this help" do usage ; raise Exit ; end
24
+ option %w(X examples ), "print this help and examples" do usage_examples ; raise Exit ; end
25
+ option %w(V version ), "print version information" do puts PROGRAM ; raise Exit ; end
26
+ option %w(v verbose ), "standard Ruby error reports" do @verbose = true ; end
27
+ option %w(o show ), "just show Ruby block built from options" do @show = true ; end
28
+ option %w(w bw ), "black and white on -p or default output" do @color = false ; end
29
+ option %w(c colored ), "force color on -p or default output" do @color = true ; end
30
+ option %w(d depth ), "yield directory after its contents" do @params[ :depth_first] = true ; end
31
+ option %w(m maxdepth ), "maxium step depth (0 = any)" do |num| @params[ :max_depth] = num.to_i.nonzero? ; end
32
+ option %w(A argsdepth ), "args have depth 1 (not 0)" do @params[ :args_depth] = true ; end
33
+ option %w(y follow ), "follow symbolic links" do @params[ :follow] = true ; end
34
+ option %w(U nosort ), "unsorted" do @params[ :sort] = false ; end
35
+ option %w(s sort-by ), "sort expression" do |str| @params[ :sort] = instance_eval "proc { #{str} }" ; end
36
+ option %w(R reverse ), "reverse the sort" do @params[ :reverse] = !@params[ :reverse] ; end
37
+ option %w(t time ), "sort by time, newest first" do @params[ :sort] = proc { mtime } ; @params[ :reverse] = true ; end
38
+ option %w(S size ), "sort by size, largest first" do @params[ :sort] = proc { size } ; @params[ :reverse] = true ; end
39
+ option %w(F dirs ), "sort directories before files" do @params[ :dirs] = true ; end
40
+ option %w(r require ), "require library" do |rb| require rb ; end
41
+ option %w(x execute ), "execute block" do |b| @block = b ; end
42
+ option %w(p puts-path ), "do 'puts path/cpath' on true block" do @puts = :plain ; end
43
+ option %w(P ls-l ), "do 'ls -l' style output on true block" do @puts = :ls ; @wds ||= 6 ; @wdu ||= 6 ; end
44
+ option %w(Q long ), "alternate long format on true block" do @puts = :alt ; @wds ||= 7 ; @wdu ||= 4 ; end
45
+ option %w(H humanage ), "long format with human readable ages" do @puts = :hum ; @wds ||= 7 ; @wdu ||= 4 ; end
46
+ option %w(J ino ), "show inodes and number of hard links" do @puts = :ino ; @wds ||= 8 ; @wdu ||= 2 ; end
47
+ option %w(+ wider ), "widen fields in long output format" do @wdu and @wdu += 2 ; @wds and @wds += @puts != :ls ? 4 : 3 ; end
48
+ option %w(/ slash ), "append a slash to directory names" do @slash = true ; end
49
+ option %w(l lines ), "surround block by 'lines { |$_,$.| ... }'" do |blk| @lines = :plain ; @block = blk ; end
50
+ option %w(L reallines ), "same as -l but stop at any null character" do |blk| @lines = :plain ; @real = true ; @block = blk ; end
51
+ option %w(g grep ), "grep files (implies -pL)" do |blk| @lines = :grep ; @block = blk ; end
52
+ option %w(G igrep ), "case insensitive grep" do |blk| @lines = :grep ; @icase = true ; @block = blk ; end
53
+ option %w(b binary ), "grep even binary files" do @binary = true ; end
54
+ option %w(C no-vcs ), "prune version control dirs (CVS/.svn/.git)" do @vcs = true ; end
55
+ option %w(W no-swap ), "ignore Vim swapfiles" do @vim = true ; end
56
+ option %w(k skip ), "filenames to skip" do |rgx| @skip = rgx ; end
57
+ option %w(D demand ), "skip all filenames but these" do |rgx| @demand = rgx ; end
58
+ option %w(e ext ), "skip all filename extensions but these" do |lst| @ext = lst ; end
59
+ option %w(I visible ), "skip all hidden (starting with .dot)" do @visible = true ; end
60
+ option %w(a all ), "all, including hidden (starting with .dot)" do @visible = false ; end
61
+ option %w(i icase ), "ignore case in file and path matches" do @icase = true ; end
62
+ option %w(N nodirs ), "skip directories" do @nodirs = true ; end
63
+ option %w(B begin ), "eval block before begin" do |blk| @blkbegin = blk ; end
64
+ option %w(E end ), "eval block after end" do |blk| @blkend = blk ; end
65
+ option %w(f file ), "read block expression from file" do |nam| @block = File.open nam do |f| f.each { |l| l.chomp! } end ; end
66
+ option %w(K encoding ), "encoding extern[:intern] (same as ruby -E)" do |str| e, i = str.split ":", 2 ; set_encoding e, i ; end
67
+ option %w( width-user), "width of user field" do |num| @wdu = num.to_i.nonzero? ; end
68
+ option %w( width-size), "width of size field" do |num| @wds = num.to_i.nonzero? ; end
69
+
70
+ def initialize args
74
71
  @params = {}
75
72
  envopts = ENV[ "RBFIND_OPTIONS"]
76
- $*.unshift *envopts.split if envopts
77
- opts = GetoptLong.new *OPTIONS.map { |names,arg,|
78
- [*names,(arg ? GetoptLong::REQUIRED_ARGUMENT : GetoptLong::NO_ARGUMENT)]
79
- }
80
- opts.ordering = GetoptLong::PERMUTE
81
- opts.quiet = true
82
- opts.each do |opt,arg|
83
- case opt
84
- when '--help' then usage ; exit
85
- when '--version' then puts PROGRAM ; exit
86
- when '--examples' then usage_examples ; exit
87
- when '--verbose' then @verbose = true
88
- when '--show' then @show = true
89
- when '--bw' then @color = false
90
- when '--colored' then @color = true
91
- when '--depth' then @params[ :depth_first] = true
92
- when '--maxdepth' then @params[ :max_depth] = arg.to_i.nonzero?
93
- when '--argsdepth' then @params[ :args_depth] = true
94
- when '--follow' then @params[ :follow] = true
95
- when '--nosort' then @params[ :sort] = false
96
- when '--sort-by' then @params[ :sort] = instance_eval "proc { #{arg} }"
97
- when '--time' then @params[ :sort] = proc { mtime } ; @params[ :reverse] = true
98
- when '--size' then @params[ :sort] = proc { size } ; @params[ :reverse] = true
99
- when '--dirs' then @params[ :dirs] = true
100
- when '--reverse' then @params[ :reverse] = !@params[ :reverse]
101
- when '--require' then require arg
102
- when '--puts-path' then @puts = true
103
- when '--ls-l' then @puts = :ls ; @wds ||= 6 ; @wdu ||= 6
104
- when '--long' then @puts = :alt ; @wds ||= 7 ; @wdu ||= 4
105
- when '--humanage' then @puts = :hum ; @wds ||= 7 ; @wdu ||= 4
106
- when '--ino' then @puts = :ino ; @wds ||= 8 ; @wdu ||= 2
107
- when '--wider' then @wdu and @wdu += 2 ; @wds and @wds += @puts != :ls ? 4 : 3
108
- when '--slash' then @slash = true
109
- when '--lines' then @lines = :plain ; @block = arg
110
- when '--reallines' then @lines = :plain ; @real = true ; @block = arg
111
- when '--grep' then @lines = :grep ; @block = arg
112
- when '--igrep' then @lines = :grep ; @icase = true ; @block = arg
113
- when '--binary' then @binary = true
114
- when '--no-vcs' then @vcs = true
115
- when '--no-swap' then @vim = true
116
- when '--skip' then @skip = arg
117
- when '--demand' then @demand = arg
118
- when '--ext' then @ext = arg
119
- when '--visible' then @visible = true
120
- when '--all' then @visible = false
121
- when '--icase' then @icase = true
122
- when '--nodirs' then @nodirs = true
123
- when '--begin' then @blkbegin = arg
124
- when '--end' then @blkend = arg
125
- when '--file' then @block = File.open arg do |f| f.each { |l| l.chomp! } end
126
- when '--encoding' then e, i = arg.split ":" ; set_encoding e, i
127
- when '--width-user' then @wdu = arg.to_i.nonzero?
128
- when '--width-size' then @wds = arg.to_i.nonzero?
73
+ if envopts then
74
+ e = []
75
+ envopts.scan /"((?:[^"\\]|\\.)*)"|'([^']*)'|(\S+)/ do
76
+ e.push $1 ? (eval $1) : ($2 || $3)
129
77
  end
78
+ args.unshift *e
130
79
  end
131
- @args = $*.dup
132
- if @args.empty? and not $stdin.tty? then
133
- $stdin.each_line { |l|
134
- l.chomp!
135
- @args.push l
136
- }
137
- end
80
+ super args
138
81
  build_block
139
- rescue GetoptLong::InvalidOption
140
- $stderr.puts $!
141
- $stderr.puts
142
- usage
143
- exit 9
144
- rescue
145
- $stderr.puts $!
146
- exit 8
147
82
  end
148
83
 
149
84
  def run
@@ -182,15 +117,12 @@ module RbFind
182
117
  (Regexp.new str, flags).inspect
183
118
  end
184
119
 
185
- def last_arg_not_a_file
120
+ def treat_last_arg_as_file
186
121
  l = @args.last
187
- return unless l
188
- return if (File.lstat l rescue false)
189
- unless l =~ /[;<>{}\[\]()*?'"!&|]/ then
190
- return if l =~ %r(\A[^ /]+/)
191
- return if l =~ %r(\A\S*/\w*[^imoxuesn]\w*\b(?!:/))
192
- end
193
- true
122
+ not l or
123
+ File.exist? l or
124
+ l.start_with? "." or
125
+ (not l =~ /[;<>{}\[\]()*?'"!&|~ ]/ and l =~ %r(/))
194
126
  end
195
127
 
196
128
  def join_code a, ind = 0
@@ -198,14 +130,10 @@ module RbFind
198
130
  when Array then
199
131
  a.map { |e| join_code e, ind + 1 }.join "\n"
200
132
  else
201
- INDENT * ind + a
133
+ INDENT * ind + a.to_s
202
134
  end
203
135
  end
204
136
 
205
- def pre_block str
206
- @block = [ str, *@block]
207
- end
208
-
209
137
  def build_block
210
138
  co = color_on $stdout
211
139
  opath = co ? "cpath" : "path"
@@ -214,7 +142,7 @@ module RbFind
214
142
  when :plain then
215
143
  @block = [ @block]
216
144
  @puts and @block = [ "if (", @block, ") then", [ "colsep #{opath}, num, line"], "end" ]
217
- @real and pre_block "break if ~/\\0/o"
145
+ @real and @block.unshift "break if ~/\\0/o"
218
146
  @block = [ "lines { |line,num|", [ "$_, $. = line, num"], @block, "}"]
219
147
 
220
148
  when :grep then
@@ -226,35 +154,33 @@ module RbFind
226
154
 
227
155
  else
228
156
  unless @block then
229
- if last_arg_not_a_file then
230
- @block = @args.pop
157
+ if treat_last_arg_as_file then
158
+ @block = "true"
159
+ @puts ||= :plain
231
160
  else
232
- @puts ||= true
161
+ @block = @args.pop
233
162
  end
234
163
  end
235
- if @puts then
236
- cond = @block
237
- @block = case @puts
238
- when :ls then long_fmt false, false, "mtime.lsish", opath, co
239
- when :alt then long_fmt true, true, "mtime.long", opath, co
240
- when :hum then long_fmt true, true, "mage.t.r4", opath, co
241
- when :ino then [ "spcsep ino.w8, nlink.w2, #{opath}"]
242
- else [ "puts #{opath}"]
243
- end
244
- @block = [ "if (", [ cond], ") then", @block, "end"] if cond
245
- end
164
+ output = case @puts
165
+ when :ls then long_fmt false, false, "mtime.lsish", opath, co
166
+ when :alt then long_fmt true, true, "mtime.long", opath, co
167
+ when :hum then long_fmt true, true, "mage.t.r4", opath, co
168
+ when :ino then [ "spcsep ino.w8, nlink.w2, #{opath}"]
169
+ when :plain then [ "puts #{opath}"]
170
+ end
171
+ output and @block = [ "if (", [ @block], ") then", output, "end"]
246
172
 
247
173
  end
248
174
 
249
175
  osic = Regexp::IGNORECASE if File::ALT_SEPARATOR || @icase
250
- @skip and pre_block "done if name =~ #{build_re @skip, osic}"
251
- @demand and pre_block "done unless name =~ #{build_re @demand, osic}"
252
- @ext and pre_block "done unless ext =~ #{build_re_ext osic}"
176
+ @skip and @block.unshift "done if name =~ #{build_re @skip, osic}"
177
+ @demand and @block.unshift "done unless name =~ #{build_re @demand, osic}"
178
+ @ext and @block.unshift "done unless ext =~ #{build_re_ext osic}"
253
179
 
254
- @visible and pre_block "done unless visible?"
255
- @nodirs and pre_block "done if dir?"
256
- @vcs and pre_block "no_vcs"
257
- @vim and pre_block "done if vimswap?"
180
+ @visible and @block.unshift "done unless visible?"
181
+ @nodirs and @block.unshift "done if dir?"
182
+ @vcs and @block.unshift "no_vcs"
183
+ @vim and @block.unshift "done if vimswap?"
258
184
 
259
185
  @params[ :error] = proc do
260
186
  case $!
@@ -275,13 +201,9 @@ module RbFind
275
201
  rbfind [options] path... 'block'
276
202
 
277
203
  EOT
278
- OPTIONS.each { |(long,short),arg,desc|
279
- puts " %-12s %2s %-5s %s" % [long,short,arg.to_s.upcase,desc]
280
- }
204
+ self.class.usage
281
205
  puts <<~'EOT'
282
206
 
283
- "--" stops option processing.
284
-
285
207
  The last argument is a block that will be executed on every found
286
208
  file object. It may be omitted; then "puts path" is assumed, or
287
209
  "puts cpath" in case the output is a terminal.
@@ -489,9 +411,8 @@ class Time
489
411
 
490
412
  # autoload several formating methods
491
413
  def method_missing sym, *args, &block
414
+ require "time" and return send sym, *args, &block
492
415
  super
493
- rescue NoMethodError, NameError
494
- send sym, *args, &block if require "time"
495
416
  end
496
417
 
497
418
  # several common schemes
@@ -566,5 +487,5 @@ class Proc
566
487
  end
567
488
 
568
489
 
569
- RbFind::Application.new.run
490
+ RbFind::RbFindAppl.run
570
491
 
@@ -0,0 +1,158 @@
1
+ #
2
+ # rbfind/appl.rb -- Option parsing etc.
3
+ #
4
+
5
+
6
+ module RbFind
7
+
8
+ class Application
9
+
10
+ class Exit < Exception ; end
11
+
12
+ class OptError < StandardError
13
+ def initialize opt
14
+ super "Unknown option: #{opt}"
15
+ end
16
+ end
17
+
18
+
19
+ class <<self
20
+
21
+ def inherited cls
22
+ cls.init_opts
23
+ end
24
+
25
+ attr_reader :options
26
+ attr_accessor :debug
27
+
28
+ def init_opts
29
+ @options, @optdocs = {}, []
30
+ end
31
+
32
+ def option names, doc, &block
33
+ names.each { |n| @options[ n] = block }
34
+ @optdocs.push [ names, doc]
35
+ end
36
+
37
+ def run
38
+ exit (new $*).run.to_i
39
+ rescue Exit
40
+ exit 0
41
+ rescue OptError
42
+ $stderr.puts $!
43
+ usage
44
+ exit 15
45
+ rescue
46
+ raise if @debug
47
+ $stderr.puts $!
48
+ exit 1
49
+ end
50
+
51
+ def usage
52
+ omax, amax, l = 0, 0, []
53
+ @optdocs.each { |names,desc|
54
+ m = names.map { |n| (n.length > 1 ? "--" : "-") + n }.join " "
55
+ omax = m.length if m.length > omax
56
+ _, arg = @options[ names.first].parameters.first
57
+ if arg then
58
+ a = arg.upcase
59
+ amax = a.length if a.length > amax
60
+ end
61
+ l.push [ m, a, desc]
62
+ }
63
+ l.push [ "--", nil, "stop option processing"]
64
+ fmt = " %%-%ds %%-%ds %%s" % [ omax, amax]
65
+ l.each { |mad| puts fmt % mad }
66
+ end
67
+
68
+ def process_options args
69
+ rest = []
70
+ loop do
71
+ arg, *args = *args
72
+ arg or break
73
+ if arg =~ /^-/ then
74
+ arg = $'
75
+ if arg =~ /^-/ then
76
+ arg = $'
77
+ if arg.empty? then
78
+ rest.concat args
79
+ break
80
+ end
81
+ arg, val = arg.split "=", 2
82
+ opt = @options[ arg] or raise OptError, "--#{arg}"
83
+ if val then
84
+ opt.parameters.empty? and raise OptError, "--#{args}=value"
85
+ yield opt, val
86
+ else
87
+ unless opt.parameters.empty? then
88
+ if opt.arity.nonzero? or args.first !~ /^-/ then
89
+ arg, *args = *args
90
+ else
91
+ arg = nil
92
+ end
93
+ end
94
+ yield opt, arg
95
+ end
96
+ else
97
+ loop do
98
+ a = arg.slice! 0, 1
99
+ a.empty? and break
100
+ opt = @options[ a] or raise OptError, "-#{a}"
101
+ if opt.parameters.empty? then
102
+ yield opt
103
+ else
104
+ if arg.empty? then
105
+ if opt.arity.nonzero? or args.first !~ /^-/ then
106
+ arg, *args = *args
107
+ end
108
+ end
109
+ yield opt, arg
110
+ break
111
+ end
112
+ end
113
+ end
114
+ else
115
+ rest.push arg
116
+ end
117
+ end
118
+ rest
119
+ end
120
+
121
+ end
122
+
123
+ def initialize args
124
+ @args = self.class.process_options args do |opt,arg|
125
+ if arg then
126
+ instance_exec arg, &opt
127
+ else
128
+ instance_exec &opt
129
+ end
130
+ end
131
+ end
132
+
133
+ end
134
+
135
+
136
+ if __FILE__ == $0 then
137
+
138
+ class DummyAppl < Application
139
+
140
+ option %w(q qqq), "Do Qs" do @q = @q.to_i.pred end
141
+ option %w(x xxx), "Do Xs" do @x = @x.to_i.succ end
142
+ option %w(y yyy), "Do Ys" do |arg| @y = arg end
143
+ option %w(z zzz), "Do Zs" do |arg=3| @z = arg end
144
+ option %w(h help), "This help" do self.class.usage ; raise Exit ; end
145
+ option %w(g debug), "Debug info" do self.class.debug = true end
146
+
147
+ def run
148
+ puts inspect
149
+ end
150
+
151
+ end
152
+
153
+ DummyAppl.run
154
+
155
+ end
156
+
157
+ end
158
+
data/lib/rbfind/core.rb CHANGED
@@ -79,4 +79,3 @@ class File
79
79
 
80
80
  end
81
81
 
82
-
data/lib/rbfind/csv.rb CHANGED
@@ -31,6 +31,7 @@ module RbFind
31
31
  def csv sep, *args
32
32
  e = args.join sep
33
33
  Csv.putl e
34
+ nil
34
35
  end
35
36
 
36
37
 
data/lib/rbfind/table.rb CHANGED
@@ -129,3 +129,4 @@ module RbFind
129
129
  end
130
130
 
131
131
  end
132
+
data/lib/rbfind.rb CHANGED
@@ -8,7 +8,7 @@ require "rbfind/csv"
8
8
 
9
9
  module RbFind
10
10
 
11
- VERSION = "2.13".freeze
11
+ VERSION = "2.14".freeze
12
12
 
13
13
  =begin rdoc
14
14
 
@@ -367,9 +367,10 @@ Sort without case sensitivity and preceding dot:
367
367
  @params.sort.call list
368
368
  list.reverse! if @params.reverse
369
369
  if @params.dirs then
370
- list.replace list.partition { |e| e.rstat.directory? rescue nil }
371
- list.reverse! if @params.depth_first
372
- list.flatten!
370
+ df = list.partition { |e| e.rstat.directory? rescue nil }
371
+ df.reverse! if @params.depth_first
372
+ list.clear
373
+ list.concat *df
373
374
  end
374
375
  end
375
376
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbfind
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.13'
4
+ version: '2.14'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-31 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: |
13
13
  A replacement for the standard UNIX command find.
@@ -20,11 +20,13 @@ executables:
20
20
  extensions: []
21
21
  extra_rdoc_files:
22
22
  - LICENSE
23
+ - README.md
23
24
  files:
24
25
  - LICENSE
25
- - README
26
+ - README.md
26
27
  - bin/rbfind
27
28
  - lib/rbfind.rb
29
+ - lib/rbfind/appl.rb
28
30
  - lib/rbfind/core.rb
29
31
  - lib/rbfind/csv.rb
30
32
  - lib/rbfind/humansiz.rb
@@ -33,11 +35,7 @@ homepage: http://www.bertram-scharpf.de/software/rbfind
33
35
  licenses:
34
36
  - BSD-2-Clause
35
37
  metadata: {}
36
- rdoc_options:
37
- - "--charset"
38
- - utf-8
39
- - "--main"
40
- - README
38
+ rdoc_options: []
41
39
  require_paths:
42
40
  - lib
43
41
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -52,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
50
  version: '0'
53
51
  requirements:
54
52
  - Just Ruby
55
- rubygems_version: 3.6.6
53
+ rubygems_version: 3.7.1
56
54
  specification_version: 4
57
55
  summary: Ruby replacement for the standard Unix find tool
58
56
  test_files: []
data/README DELETED
@@ -1,45 +0,0 @@
1
- = RbFind
2
-
3
- A substitute for the Unix find tool using Ruby expressions
4
-
5
- == Description
6
-
7
- RbFind does the same as the standard Unix find tool but has a
8
- different calling syntax. You may specify your search reqest as a
9
- Ruby expression.
10
-
11
- == Features
12
-
13
- * ls long format style output
14
- * Built-in grep
15
- * Colored ls and grep output
16
- * Automatically exclude version control system or Vim swap files
17
- * No dependecies
18
-
19
- == Example
20
-
21
- Find files that were modified in the last five minutes.
22
-
23
- $ rbfind -p 'file and age < 5.m'
24
-
25
- Grep whole directory but skip ".git/" or ".svn/", and
26
- ".filename.swp".
27
-
28
- $ rbfind -CWg require
29
-
30
- Save time and do not grep large files.
31
-
32
- $ rbfind 'filesize < 100.kB and grep /require/'
33
-
34
- Output ls long format.
35
-
36
- $ rbfind -P
37
-
38
- Print MD5 digest and size for each file.
39
-
40
- $ rbfind 'spacesep digest_md5, size.w8, path'
41
-
42
- == Copyright
43
-
44
- (C) 2008-2014, Bertram Scharpf <software@bertram-scharpf.de>
45
-