rbfind 2.8.6 → 2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rbfind +229 -192
- data/lib/rbfind/core.rb +18 -18
- data/lib/rbfind/humansiz.rb +5 -4
- data/lib/rbfind/table.rb +7 -7
- data/lib/rbfind.rb +16 -18
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa9bf2ca868c2a2d061907c5fd2aff5e7fc0b16efca5a2cfce29ab760839444b
|
4
|
+
data.tar.gz: a739af2888f22b85c1780166dbf029273b7e76581d11fe0969bcdec8229ee66e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4687e55164883d414875e4bc2a9ee6dcc7e9ee06d17b9db0ef26411f68e4492fc21e29675ee28636d95e5bd088feacfe729fe4fa3eeb618a2d63f06349c46d55
|
7
|
+
data.tar.gz: 0d4a00f2d0ab6cae193cfa05d473127613e97560b65824bc80f449b5f955d6ddce4609b159dad1dba5c0504a1c91a603e98407c725c1ae1ac71d557c5684e119
|
data/bin/rbfind
CHANGED
@@ -44,6 +44,7 @@ module RbFind
|
|
44
44
|
[ %w(--puts-path -p), nil, "do 'puts path/cpath' on true block"],
|
45
45
|
[ %w(--ls-l -P), nil, "do 'ls -l' style output on true block"],
|
46
46
|
[ %w(--long -Q), nil, "alternate long format on true block"],
|
47
|
+
[ %w(--humanage -H), nil, "long format with human readable ages"],
|
47
48
|
[ %w(--ino -J), nil, "show inodes and number of hard links"],
|
48
49
|
[ %w(--wider -+), nil, "widen fields in long output format"],
|
49
50
|
[ %w(--slash -/), nil, "append a slash to directory names"],
|
@@ -59,6 +60,7 @@ module RbFind
|
|
59
60
|
[ %w(--ext -e), :lst, "skip all filename extensions but these"],
|
60
61
|
[ %w(--visible -I), nil, "skip all hidden (starting with .dot)"],
|
61
62
|
[ %w(--all -a), nil, "all, including hidden (starting with .dot)"],
|
63
|
+
[ %w(--icase -i), nil, "ignore case in file and path matches"],
|
62
64
|
[ %w(--nodirs -N), nil, "skip directories"],
|
63
65
|
[ %w(--begin -B), :blk, "eval block before begin"],
|
64
66
|
[ %w(--end -E), :blk, "eval block after end"],
|
@@ -77,47 +79,49 @@ module RbFind
|
|
77
79
|
opts.quiet = true
|
78
80
|
opts.each do |opt,arg|
|
79
81
|
case opt
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
82
|
+
when '--help' then usage ; exit
|
83
|
+
when '--version' then puts PROGRAM ; exit
|
84
|
+
when '--examples' then usage_examples ; exit
|
85
|
+
when '--verbose' then @verbose = true
|
86
|
+
when '--show' then @show = true
|
87
|
+
when '--bw' then @color = false
|
88
|
+
when '--colored' then @color = true
|
89
|
+
when '--depth' then @params[ :depth_first] = true
|
90
|
+
when '--maxdepth' then @params[ :max_depth] = arg.to_i.nonzero?
|
91
|
+
when '--argsdepth' then @params[ :args_depth] = true
|
92
|
+
when '--follow' then @params[ :follow] = true
|
93
|
+
when '--nosort' then @params[ :sort] = false
|
94
|
+
when '--sort-by' then @params[ :sort] = instance_eval "proc { #{arg} }"
|
95
|
+
when '--time' then @params[ :sort] = proc { mtime } ; @params[ :reverse] = true
|
96
|
+
when '--size' then @params[ :sort] = proc { size } ; @params[ :reverse] = true
|
97
|
+
when '--dirs' then @params[ :dirs] = true
|
98
|
+
when '--reverse' then @params[ :reverse] = !@params[ :reverse]
|
99
|
+
when '--require' then require arg
|
100
|
+
when '--puts-path' then @puts = true
|
101
|
+
when '--ls-l' then @puts = :ls ; @wds = 6 ; @wd = 6
|
102
|
+
when '--long' then @puts = :alt ; @wds = 7 ; @wd = 4
|
103
|
+
when '--humanage' then @puts = :hum ; @wds = 7 ; @wd = 4
|
104
|
+
when '--ino' then @puts = :ino ; @wds = 8 ; @wd = 2
|
105
|
+
when '--wider' then @wd and @wd += 2 ; @wds and @wds += @puts != :ls ? 4 : 3
|
106
|
+
when '--slash' then @slash = true
|
107
|
+
when '--lines' then @lines = :plain ; @block = arg
|
108
|
+
when '--reallines' then @lines = :plain ; @real = true ; @block = arg
|
109
|
+
when '--grep' then @lines = :grep ; @block = arg
|
110
|
+
when '--igrep' then @lines = :grep ; @icase = true ; @block = arg
|
111
|
+
when '--binary' then @binary = true
|
112
|
+
when '--no-vcs' then @vcs = true
|
113
|
+
when '--no-swap' then @vim = true
|
114
|
+
when '--skip' then @skip = arg
|
115
|
+
when '--demand' then @demand = arg
|
116
|
+
when '--ext' then @ext = arg
|
117
|
+
when '--visible' then @visible = true
|
118
|
+
when '--all' then @visible = false
|
119
|
+
when '--icase' then @icase = true
|
120
|
+
when '--nodirs' then @nodirs = true
|
121
|
+
when '--begin' then @blkbegin = arg
|
122
|
+
when '--end' then @blkend = arg
|
123
|
+
when '--file' then @block = File.open arg do |f| f.each { |l| l.chomp! } end
|
124
|
+
when '--encoding' then e, i = arg.split ":" ; set_encoding e, i
|
121
125
|
end
|
122
126
|
end
|
123
127
|
@args = $*.dup
|
@@ -138,91 +142,126 @@ module RbFind
|
|
138
142
|
exit 8
|
139
143
|
end
|
140
144
|
|
145
|
+
def run
|
146
|
+
if @show then
|
147
|
+
show
|
148
|
+
else
|
149
|
+
execute
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
private
|
154
|
+
|
155
|
+
INDENT = " "*2
|
156
|
+
|
157
|
+
def long_fmt ug_bang, grp, time, opath, co
|
158
|
+
b = "!" if ug_bang
|
159
|
+
g = "_" if grp
|
160
|
+
[
|
161
|
+
"spcsep stype+modes,",
|
162
|
+
[
|
163
|
+
"user#{b}.w#@wd, group#{b}.w#@wd,",
|
164
|
+
"size.w#{g}#@wds, #{time},",
|
165
|
+
"#{opath} + #{co ? 'carrow' : 'arrow'}.to_s",
|
166
|
+
]
|
167
|
+
]
|
168
|
+
end
|
169
|
+
|
170
|
+
def build_re str, flags
|
171
|
+
(Regexp.new str, flags).inspect
|
172
|
+
end
|
173
|
+
|
174
|
+
def build_re_ext flags
|
175
|
+
exts = @ext.split(/ +|,/).map { |e| e.delete_prefix! "." ; e }
|
176
|
+
ej = exts.join '|'
|
177
|
+
str = '\A\.(' + ej + ')\z'
|
178
|
+
(Regexp.new str, flags).inspect
|
179
|
+
end
|
180
|
+
|
181
|
+
def last_arg_not_a_file
|
182
|
+
l = @args.last
|
183
|
+
return unless l
|
184
|
+
return if (File.lstat l rescue false)
|
185
|
+
unless l =~ /[;<>{}\[\]()*?'"!&|]/ then
|
186
|
+
return if l =~ %r(\A[^ /]+/)
|
187
|
+
return if l =~ %r(\A\S*/\w*[^imoxuesn]\w*\b(?!:/))
|
188
|
+
end
|
189
|
+
true
|
190
|
+
end
|
191
|
+
|
192
|
+
def join_code a, ind = 0
|
193
|
+
case a
|
194
|
+
when Array then
|
195
|
+
a.map { |e| join_code e, ind + 1 }.join "\n"
|
196
|
+
else
|
197
|
+
INDENT * ind + a
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def pre_block str
|
202
|
+
@block = [ str, *@block]
|
203
|
+
end
|
204
|
+
|
141
205
|
def build_block
|
142
206
|
co = color_on $stdout
|
143
207
|
opath = co ? "cpath" : "path"
|
144
208
|
@slash and opath << "!"
|
145
209
|
case @lines
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
210
|
+
when :plain then
|
211
|
+
@block = [ @block]
|
212
|
+
@puts and @block = [ "if (", @block, ") then", [ "colsep #{opath}, num, line"], "end" ]
|
213
|
+
@real and pre_block "break if ~/\\0/o"
|
214
|
+
@block = [ "lines { |line,num|", [ "$_, $. = line, num"], @block, "}"]
|
215
|
+
|
216
|
+
when :grep then
|
217
|
+
ic = Regexp::IGNORECASE if @icase
|
218
|
+
color = ", true" if co
|
219
|
+
@block = [ "grep %r#{build_re @block, ic}#{color}"]
|
220
|
+
@block.push "$stdout.flush" unless $stdout.tty?
|
221
|
+
@binary or @block = [ "unless binary? then", @block, "end"]
|
222
|
+
|
223
|
+
else
|
224
|
+
unless @block then
|
225
|
+
if last_arg_not_a_file then
|
226
|
+
@block = @args.pop
|
161
227
|
else
|
162
228
|
@puts ||= true
|
163
|
-
"true"
|
164
229
|
end
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
when :ino then
|
175
|
-
"spcsep ino.w#@wds, nlink.w#@wd, #{opath}"
|
176
|
-
else
|
177
|
-
"puts #{opath}"
|
230
|
+
end
|
231
|
+
if @puts then
|
232
|
+
cond = @block
|
233
|
+
@block = case @puts
|
234
|
+
when :ls then long_fmt false, false, "mtime.lsish", opath, co
|
235
|
+
when :alt then long_fmt true, true, "mtime.long", opath, co
|
236
|
+
when :hum then long_fmt true, true, "mage.t.r4", opath, co
|
237
|
+
when :ino then [ "spcsep ino.w#@wds, nlink.w#@wd, #{opath}"]
|
238
|
+
else [ "puts #{opath}"]
|
178
239
|
end
|
179
|
-
end
|
180
|
-
|
181
|
-
end
|
182
|
-
|
183
|
-
osic = File::ALT_SEPARATOR&&Regexp::IGNORECASE
|
184
|
-
if @skip then
|
185
|
-
re = Regexp.new @skip, osic
|
186
|
-
@block.insert 0, "done if name =~ #{re.inspect} ; "
|
187
|
-
end
|
188
|
-
|
189
|
-
if @demand then
|
190
|
-
re = Regexp.new @demand, osic
|
191
|
-
@block.insert 0, "done unless name =~ #{re.inspect} ; "
|
192
|
-
end
|
240
|
+
@block = [ "if (", [ cond], ") then", @block, "end"] if cond
|
241
|
+
end
|
193
242
|
|
194
|
-
if @ext then
|
195
|
-
re = Regexp.new '\A\.(' +
|
196
|
-
@ext.split(/ +|,/).map { |e| e[ /\A\.?(.*)\z/, 1] }.join('|') +
|
197
|
-
')\z', osic
|
198
|
-
@block.insert 0, "ext =~ #{re.inspect} or done ; "
|
199
243
|
end
|
200
244
|
|
201
|
-
|
202
|
-
|
203
|
-
@
|
245
|
+
osic = Regexp::IGNORECASE if File::ALT_SEPARATOR || @icase
|
246
|
+
@skip and pre_block "done if name =~ #{build_re @skip, osic}"
|
247
|
+
@demand and pre_block "done unless name =~ #{build_re @demand, osic}"
|
248
|
+
@ext and pre_block "done unless ext =~ #{build_re_ext osic}"
|
204
249
|
|
205
|
-
@
|
206
|
-
@
|
250
|
+
@visible and pre_block "done unless visible?"
|
251
|
+
@nodirs and pre_block "done if dir?"
|
252
|
+
@vcs and pre_block "no_vcs"
|
253
|
+
@vim and pre_block "done if vimswap?"
|
207
254
|
|
208
255
|
@params[ :error] = proc do
|
209
256
|
case $!
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
257
|
+
when Errno::EPIPE then raise
|
258
|
+
when NameError, TypeError then raise
|
259
|
+
when ArgumentError then raise
|
260
|
+
else show_error $!
|
214
261
|
end
|
215
262
|
end
|
216
263
|
end
|
217
264
|
|
218
|
-
def run
|
219
|
-
if @show then
|
220
|
-
show
|
221
|
-
else
|
222
|
-
execute
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
265
|
private
|
227
266
|
|
228
267
|
def usage
|
@@ -250,56 +289,56 @@ module RbFind
|
|
250
289
|
def usage_examples
|
251
290
|
usage
|
252
291
|
puts <<~'EOT'
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
292
|
+
Examples:
|
293
|
+
$ rbfind -p 'file and age < 5.m'
|
294
|
+
$ rbfind -p 'file and age > 1.d'
|
295
|
+
$ rbfind -p '(90.d .. 183.d) === age'
|
296
|
+
|
297
|
+
$ rbfind -Cg require
|
298
|
+
$ rbfind -Cp
|
299
|
+
$ rbfind 'filesize < 100.kB and grep /require/'
|
300
|
+
$ rbfind -g 'define\s*ALLOC_N'
|
301
|
+
$ rbfind myproject -e rb -l '~/require/ and puts $_'
|
302
|
+
|
303
|
+
$ rbfind -pe '.rb c h'
|
304
|
+
$ rbfind /usr/include -e .h -g EACCES
|
305
|
+
$ rbfind -d -m3 -- /mnt/data
|
306
|
+
$ rbfind 'filesize > 10.MiB and colsep size.to_hib, path'
|
307
|
+
|
308
|
+
$ rbfind -U "name =~ /^\.*/ ; $'.downcase"
|
309
|
+
$ rbfind -B '$s=0' -E 'puts $s.to_h' 'filesize {|s|$s+=s}'
|
310
|
+
$ rbfind 'puts path if ext == ".rb"'
|
311
|
+
$ rbfind -p 'ext == ".rb"'
|
312
|
+
$ rbfind /usr/include -p -D '\.h$' -l '~/EACCES/'
|
313
|
+
$ rbfind /usr/include -pD 'pg|pq|postgres' dir
|
314
|
+
$ rbfind 'no_svn ; puts path'
|
315
|
+
$ rbfind 'prune if name == ".svn" ; puts path'
|
316
|
+
$ rbfind -p 'prune if name == ".svn"'
|
317
|
+
$ rbfind myproject 'name[/\.rb$/] and lines { |l,i| l=~/require/ and puts l }'
|
318
|
+
# rbfind /etc 'lines { |l,| l["192.168."] and (puts path ; break) }'
|
319
|
+
$ rbfind /etc 'readable? or raise "Access denied: #{path}" ;
|
320
|
+
> lines { |l,| l["192.168."] and (puts path ; break) }'
|
321
|
+
|
322
|
+
$ rbfind 'col_sep stype+modes, size.w10, path'
|
323
|
+
$ rbfind 'tab_sep stype+modes, size.w10, path'
|
324
|
+
$ rbfind 'spc_sep stype+modes, size.to_h, user, group, mtime.lsish, path'
|
325
|
+
$ rbfind 'p stype+modes, size.to_h, user, group, mtime.lsish, path'
|
326
|
+
$ rbfind 'p stype+modes, size.to_h, user, group, mtime!, path'
|
327
|
+
$ rbfind 'p stype+modes, size.to_h, user, group, mtime.i, path'
|
328
|
+
$ rbfind 'p mtime.u, path'
|
329
|
+
$ rbfind 'p modes, user.w8, group.w8, size.w8, cpath + carrow.to_s'
|
330
|
+
|
331
|
+
$ rbfind 'p digest_md5, size.w8, path'
|
332
|
+
$ rbfind 'p digest_sha256, size.w8, path'
|
333
|
+
|
334
|
+
$ rbfind 'rename name.downcase'
|
335
|
+
$ rbfind 'ext == ".tgz" and rename without_ext+".tar.gz"'
|
336
|
+
|
337
|
+
See the RbFind documentation or the "rbfind.rb" source file for more
|
338
|
+
sophisticated examples and for a full list of file examination methods.
|
339
|
+
|
340
|
+
Valid units are 1.s, 1.m, 1.h, 1.d, 1.w for time values and
|
341
|
+
1.kB == 1000, 1.kiB == 1024, 1.MB, 1.MiB for file sizes.
|
303
342
|
EOT
|
304
343
|
end
|
305
344
|
|
@@ -357,7 +396,7 @@ module RbFind
|
|
357
396
|
def execute
|
358
397
|
error_handle do
|
359
398
|
eval @blkbegin if @blkbegin
|
360
|
-
b = @block
|
399
|
+
b = join_code @block
|
361
400
|
Walk.run *@args, **@params do instance_eval b end
|
362
401
|
eval @blkend if @blkend
|
363
402
|
end
|
@@ -369,11 +408,10 @@ module RbFind
|
|
369
408
|
puts "parameters:"
|
370
409
|
@params.each { |k,v| puts_val k, "=", v }.any? or puts_val "(none)"
|
371
410
|
puts "block:"
|
372
|
-
|
411
|
+
c = join_code @block, 1
|
412
|
+
puts c
|
373
413
|
end
|
374
414
|
|
375
|
-
INDENT = " "*2
|
376
|
-
|
377
415
|
def puts_val *args
|
378
416
|
l = [ INDENT, *args].join ""
|
379
417
|
puts l
|
@@ -419,22 +457,22 @@ module RbFind
|
|
419
457
|
alias method_missing_orig method_missing
|
420
458
|
def method_missing sym, *args, &block
|
421
459
|
case sym.to_s
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
460
|
+
when /\Adigest_(.*)/, /\A([a-z]+[0-9]+)\z/ then
|
461
|
+
m = $1
|
462
|
+
d = begin
|
463
|
+
Digest.const_get m.upcase
|
464
|
+
rescue NameError
|
465
|
+
if m =~ /sha\d\d\d/ then m = "sha2" end
|
466
|
+
require "digest/#{m}" and retry
|
467
|
+
raise
|
468
|
+
end
|
469
|
+
e = d.new
|
470
|
+
read 0x1000_0000 do |b| e.update b end
|
471
|
+
e.hexdigest
|
472
|
+
when /\A([amc]time)!\z/ then
|
473
|
+
(send $1).strftime "%Y-%m-%d %H:%M:%S %z"
|
474
|
+
else
|
475
|
+
method_missing_orig sym, *args, &block
|
438
476
|
end
|
439
477
|
end
|
440
478
|
|
@@ -447,11 +485,9 @@ class Time
|
|
447
485
|
|
448
486
|
# autoload several formating methods
|
449
487
|
def method_missing sym, *args, &block
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
super
|
454
|
-
end
|
488
|
+
super
|
489
|
+
rescue NoMethodError
|
490
|
+
send sym, *args, &block if require "time"
|
455
491
|
end
|
456
492
|
|
457
493
|
# several common schemes
|
@@ -466,20 +502,21 @@ end
|
|
466
502
|
class Integer
|
467
503
|
# convenient formatting, right justification
|
468
504
|
def method_missing sym, *args
|
469
|
-
case sym
|
470
|
-
|
471
|
-
|
472
|
-
|
505
|
+
case sym
|
506
|
+
when /\Aw(\d+)/ then "%#{$1}d" % self
|
507
|
+
when /\Aw_(\d+)/ then to_g.rjust $1.to_i
|
508
|
+
else super
|
473
509
|
end
|
474
510
|
end
|
475
511
|
end
|
476
512
|
|
477
513
|
class String
|
478
|
-
# convenient formatting, left justification
|
514
|
+
# convenient formatting, left and right justification
|
479
515
|
def method_missing sym, *args
|
480
|
-
case sym
|
481
|
-
|
482
|
-
|
516
|
+
case sym
|
517
|
+
when /\Aw_?(\d+)/ then ljust $1.to_i
|
518
|
+
when /\Ar_?(\d+)/ then rjust $1.to_i
|
519
|
+
else super
|
483
520
|
end
|
484
521
|
end
|
485
522
|
# conventient date/time construction
|
@@ -497,9 +534,9 @@ class NilClass
|
|
497
534
|
def between? min, max ; false ; end
|
498
535
|
|
499
536
|
def method_missing sym, *args
|
500
|
-
case sym
|
501
|
-
|
502
|
-
|
537
|
+
case sym
|
538
|
+
when /\A[wr]_?(\d+)/ then " "*$1.to_i
|
539
|
+
else super
|
503
540
|
end
|
504
541
|
end
|
505
542
|
end
|
data/lib/rbfind/core.rb
CHANGED
@@ -34,29 +34,29 @@ class File
|
|
34
34
|
|
35
35
|
def stype
|
36
36
|
case mode >> 12
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
when 001 then "p"
|
38
|
+
when 002 then "c"
|
39
|
+
when 004 then "d"
|
40
|
+
when 006 then "b"
|
41
|
+
when 010 then "-"
|
42
|
+
when 012 then "l"
|
43
|
+
when 014 then "s"
|
44
|
+
when 016 then "w"
|
45
|
+
else "?"
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
def suffix
|
50
50
|
case mode >> 12
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
when 001 then "|"
|
52
|
+
when 002 then " "
|
53
|
+
when 004 then "/"
|
54
|
+
when 006 then " "
|
55
|
+
when 010 then executable? ? "*" : " "
|
56
|
+
when 012 then "@"
|
57
|
+
when 014 then "="
|
58
|
+
when 016 then "%"
|
59
|
+
else "?"
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
data/lib/rbfind/humansiz.rb
CHANGED
@@ -103,19 +103,20 @@ end
|
|
103
103
|
|
104
104
|
class Time
|
105
105
|
|
106
|
-
TIME_UNITS =
|
106
|
+
TIME_UNITS = { seconds: 60, minutes: 60, hours: 24, days: 7, weeks: nil }
|
107
107
|
class <<self
|
108
108
|
def to_unit n
|
109
|
-
u = TIME_UNITS.
|
109
|
+
u = TIME_UNITS.each_pair do |nam,val|
|
110
110
|
break nam if not val or n < val
|
111
111
|
n /= val
|
112
112
|
end
|
113
113
|
"#{n}#{u[0]}"
|
114
114
|
end
|
115
115
|
def to_sec num, unit
|
116
|
-
TIME_UNITS.
|
116
|
+
TIME_UNITS.each_pair do |nam,val|
|
117
117
|
return num if nam.start_with? unit
|
118
|
-
num *= val
|
118
|
+
num *= val.to_i
|
119
|
+
num.nonzero? or break
|
119
120
|
end
|
120
121
|
raise "No time unit: #{unit}."
|
121
122
|
end
|
data/lib/rbfind/table.rb
CHANGED
@@ -14,7 +14,7 @@ module RbFind
|
|
14
14
|
when />\z/ then +1
|
15
15
|
when /\^\z/ then 0
|
16
16
|
when /<?\z/ then -1
|
17
|
-
|
17
|
+
end
|
18
18
|
[ $`, a]
|
19
19
|
}
|
20
20
|
@rows = []
|
@@ -58,9 +58,9 @@ module RbFind
|
|
58
58
|
j = (w.zip @heads, r).map { |v,(_,a),c|
|
59
59
|
c ||= ""
|
60
60
|
case a
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
when -1 then c.ljust v
|
62
|
+
when 0 then c.center v
|
63
|
+
when +1 then c.rjust v
|
64
64
|
end
|
65
65
|
}
|
66
66
|
l = j.join " "
|
@@ -120,9 +120,9 @@ module RbFind
|
|
120
120
|
|
121
121
|
def html_align a
|
122
122
|
case a
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
when -1 then "left"
|
124
|
+
when 0 then "center"
|
125
|
+
when +1 then "right"
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
data/lib/rbfind.rb
CHANGED
@@ -8,7 +8,7 @@ require "rbfind/csv"
|
|
8
8
|
|
9
9
|
module RbFind
|
10
10
|
|
11
|
-
VERSION = "2.
|
11
|
+
VERSION = "2.9".freeze
|
12
12
|
|
13
13
|
=begin rdoc
|
14
14
|
|
@@ -284,10 +284,10 @@ Sort without case sensitivity and preceding dot:
|
|
284
284
|
|
285
285
|
def sort_parser st
|
286
286
|
case st
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
287
|
+
when Proc then proc { |l| l.sort_by! { |e| e.instance_eval &st } }
|
288
|
+
when String then proc { |l| l.sort_by! { |e| e.instance_eval st } }
|
289
|
+
when nil, false then proc { }
|
290
|
+
else proc { |l| l.sort_by! { |e| e.name } }
|
291
291
|
end
|
292
292
|
end
|
293
293
|
|
@@ -386,7 +386,6 @@ Sort without case sensitivity and preceding dot:
|
|
386
386
|
def call_block
|
387
387
|
handle_error do
|
388
388
|
begin
|
389
|
-
$_, $. = @current.name, @count
|
390
389
|
@current.instance_eval &@params.block
|
391
390
|
rescue Done
|
392
391
|
end
|
@@ -397,9 +396,9 @@ Sort without case sensitivity and preceding dot:
|
|
397
396
|
yield
|
398
397
|
rescue
|
399
398
|
case @params.error
|
400
|
-
|
401
|
-
|
402
|
-
|
399
|
+
when Proc then @params.error.call
|
400
|
+
when String then instance_eval @params.error
|
401
|
+
else raise
|
403
402
|
end
|
404
403
|
nil
|
405
404
|
end
|
@@ -651,7 +650,6 @@ Sort without case sensitivity and preceding dot:
|
|
651
650
|
file.each_line { |l|
|
652
651
|
l.chomp!
|
653
652
|
n += 1
|
654
|
-
$_, $. = l, n
|
655
653
|
r ||= true if yield l, n
|
656
654
|
}
|
657
655
|
r
|
@@ -660,9 +658,9 @@ Sort without case sensitivity and preceding dot:
|
|
660
658
|
|
661
659
|
def grep re, color = nil
|
662
660
|
case color
|
663
|
-
|
664
|
-
|
665
|
-
|
661
|
+
when /\A\d+(?:;\d+)*\z/, nil, false then
|
662
|
+
when true then color = "31;1" # red
|
663
|
+
else raise "Illegal color spec: #{color}"
|
666
664
|
end
|
667
665
|
lines { |l,i|
|
668
666
|
l.scrub!
|
@@ -795,7 +793,7 @@ Sort without case sensitivity and preceding dot:
|
|
795
793
|
when 016 then 13
|
796
794
|
when nil then 1
|
797
795
|
else 14
|
798
|
-
|
796
|
+
end
|
799
797
|
self.class.colored arg, code
|
800
798
|
end
|
801
799
|
|
@@ -803,8 +801,8 @@ Sort without case sensitivity and preceding dot:
|
|
803
801
|
# Overwrite this to define custom colors
|
804
802
|
# Example:
|
805
803
|
# case ext
|
806
|
-
#
|
807
|
-
#
|
804
|
+
# when ".png", /\.jpe?g$/, /\.tiff?$/ then 15
|
805
|
+
# when /\.tar\.(gz|bz2)$/ then 16
|
808
806
|
# end
|
809
807
|
end
|
810
808
|
|
@@ -832,11 +830,11 @@ Sort without case sensitivity and preceding dot:
|
|
832
830
|
fg, bg = $~.captures.map { |x| x.downcase.ord - ?a.ord }
|
833
831
|
a = []
|
834
832
|
case fg
|
835
|
-
|
833
|
+
when 0..7 then a.push 30 + fg
|
836
834
|
end
|
837
835
|
a.push 1 if $1 == $1.upcase
|
838
836
|
case bg
|
839
|
-
|
837
|
+
when 0..7 then a.push 40 + bg
|
840
838
|
end
|
841
839
|
e = a.join ";"
|
842
840
|
cols.push e
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbfind
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: '2.9'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bertram Scharpf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
A replacement for the standard UNIX command find.
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
version: '0'
|
55
55
|
requirements:
|
56
56
|
- just Ruby
|
57
|
-
rubygems_version: 3.
|
57
|
+
rubygems_version: 3.4.20
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: Ruby replacement for the standard Unix find tool
|