rbfind 2.5 → 2.8.2
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/bin/rbfind +40 -19
- data/lib/rbfind.rb +60 -33
- data/lib/rbfind/humansiz.rb +16 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 673e3195f462c1f8b06eeb61423bc73811a84e28f191f963af2c546d43717f4a
|
|
4
|
+
data.tar.gz: 20218e28ea03d78c4e0dba0bbf2aa2a2d8ae484839075eee8bfbec013efd2916
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 44276ce8399adf25ad8bcfad934522d5667ba8120d8d44bcda05fd705d272512a3a5302a0419b1a6d87049a948418df2d5c7c45a49603aba531a3096da103a86
|
|
7
|
+
data.tar.gz: 24d752cffc2e7669e60b225d6ce1108c9b0d51006215602e564daeeea1ccc2e6ad06ee306674109c371ffa28adb6da71b3f34e487959782abdba12dd71888f69
|
data/bin/rbfind
CHANGED
|
@@ -31,15 +31,21 @@ module RbFind
|
|
|
31
31
|
[ %w(--bw -w), nil, "black and white on -p or default output"],
|
|
32
32
|
[ %w(--colored -c), nil, "force color on -p or default output"],
|
|
33
33
|
[ %w(--depth -d), nil, "yield directory after its contents"],
|
|
34
|
-
[ %w(--maxdepth -m), :num, "maxium step depth"],
|
|
34
|
+
[ %w(--maxdepth -m), :num, "maxium step depth (0 = any)"],
|
|
35
|
+
[ %w(--argsdepth -A), nil, "args have depth 1 (not 0)"],
|
|
35
36
|
[ %w(--follow -y), nil, "follow symbolic links"],
|
|
36
|
-
[ %w(--nosort -
|
|
37
|
+
[ %w(--nosort -U), nil, "unsorted"],
|
|
37
38
|
[ %w(--sort-by -s), :str, "sort expression"],
|
|
38
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"],
|
|
39
43
|
[ %w(--require -r), :rb, "require library"],
|
|
40
44
|
[ %w(--puts-path -p), nil, "do 'puts path/cpath' on true block"],
|
|
41
45
|
[ %w(--ls-l -P), nil, "do 'ls -l' style output on true block"],
|
|
42
|
-
[ %w(--
|
|
46
|
+
[ %w(--long -Q), nil, "alternate long format on true block"],
|
|
47
|
+
[ %w(--ino -J), nil, "show inodes and number of hard links"],
|
|
48
|
+
[ %w(--wider -+), nil, "widen fields in long output format"],
|
|
43
49
|
[ %w(--slash -/), nil, "append a slash to directory names"],
|
|
44
50
|
[ %w(--lines -l), :blk, "surround block by 'lines { |$_,$.| ... }'"],
|
|
45
51
|
[ %w(--reallines -L), :blk, "same as -l but stop at any null character"],
|
|
@@ -52,6 +58,7 @@ module RbFind
|
|
|
52
58
|
[ %w(--demand -D), :rgx, "skip all filenames but these"],
|
|
53
59
|
[ %w(--ext -e), :lst, "skip all filename extensions but these"],
|
|
54
60
|
[ %w(--visible -I), nil, "skip all hidden (starting with .dot)"],
|
|
61
|
+
[ %w(--all -a), nil, "all, including hidden (starting with .dot)"],
|
|
55
62
|
[ %w(--nodirs -N), nil, "skip directories"],
|
|
56
63
|
[ %w(--begin -B), :blk, "eval block before begin"],
|
|
57
64
|
[ %w(--end -E), :blk, "eval block after end"],
|
|
@@ -78,15 +85,21 @@ module RbFind
|
|
|
78
85
|
when '--bw' then @color = false
|
|
79
86
|
when '--colored' then @color = true
|
|
80
87
|
when '--depth' then @params[ :depth_first] = true
|
|
81
|
-
when '--maxdepth' then @params[ :max_depth] = arg.to_i
|
|
88
|
+
when '--maxdepth' then @params[ :max_depth] = arg.to_i.nonzero?
|
|
89
|
+
when '--argsdepth' then @params[ :args_depth] = true
|
|
82
90
|
when '--follow' then @params[ :follow] = true
|
|
83
91
|
when '--nosort' then @params[ :sort] = false
|
|
84
|
-
when '--sort-by' then @params[ :sort] = instance_eval "proc {
|
|
92
|
+
when '--sort-by' then @params[ :sort] = instance_eval "proc { #{arg} }"
|
|
93
|
+
when '--time' then @params[ :sort] = proc { mtime } ; @params[ :reverse] = true
|
|
94
|
+
when '--size' then @params[ :sort] = proc { size } ; @params[ :reverse] = true
|
|
95
|
+
when '--dirs' then @params[ :dirs] = true
|
|
85
96
|
when '--reverse' then @params[ :reverse] = true
|
|
86
97
|
when '--require' then require arg
|
|
87
98
|
when '--puts-path' then @puts = true
|
|
88
|
-
when '--ls-l' then @puts =
|
|
89
|
-
when '--
|
|
99
|
+
when '--ls-l' then @puts = :ls ; @wds = 6 ; @wd = 6
|
|
100
|
+
when '--long' then @puts = :alt ; @wds = 7 ; @wd = 4
|
|
101
|
+
when '--ino' then @puts = :ino ; @wds = 8 ; @wd = 2
|
|
102
|
+
when '--wider' then @wd and @wd += 2.succ ; @wds and @wds += @puts != :ls ? 4 : 3
|
|
90
103
|
when '--slash' then @slash = true
|
|
91
104
|
when '--lines' then @lines = :plain ; @block = arg
|
|
92
105
|
when '--reallines' then @lines = :plain ; @real = true ; @block = arg
|
|
@@ -99,6 +112,7 @@ module RbFind
|
|
|
99
112
|
when '--demand' then @demand = arg
|
|
100
113
|
when '--ext' then @ext = arg
|
|
101
114
|
when '--visible' then @visible = true
|
|
115
|
+
when '--all' then @visible = false
|
|
102
116
|
when '--nodirs' then @nodirs = true
|
|
103
117
|
when '--begin' then @blkbegin = arg
|
|
104
118
|
when '--end' then @blkend = arg
|
|
@@ -150,11 +164,17 @@ module RbFind
|
|
|
150
164
|
end
|
|
151
165
|
if @puts then
|
|
152
166
|
@block = "( #@block ) and "
|
|
153
|
-
@block <<
|
|
154
|
-
|
|
155
|
-
"
|
|
156
|
-
|
|
157
|
-
|
|
167
|
+
@block << case @puts
|
|
168
|
+
when :ls then
|
|
169
|
+
"spcsep stype+modes, user.w#@wd, group.w#@wd, size.w#@wds, " +
|
|
170
|
+
"mtime.lsish, #{opath} + #{co ? 'carrow' : 'arrow'}.to_s"
|
|
171
|
+
when :alt then
|
|
172
|
+
"spcsep stype+modes, user!.w#@wd, group!.w#@wd, size.w_#@wds, " +
|
|
173
|
+
"mtime.long, #{opath} + #{co ? 'carrow' : 'arrow'}.to_s"
|
|
174
|
+
when :ino then
|
|
175
|
+
"spcsep ino.w#@wds, nlink.w#@wd, #{opath}"
|
|
176
|
+
else
|
|
177
|
+
"puts #{opath}"
|
|
158
178
|
end
|
|
159
179
|
end
|
|
160
180
|
|
|
@@ -220,10 +240,10 @@ module RbFind
|
|
|
220
240
|
"--" stops option processing.
|
|
221
241
|
|
|
222
242
|
The last argument is a block that will be executed on every found
|
|
223
|
-
file object. It may be omitted; then "puts path" is assumed or
|
|
224
|
-
in case the output is a terminal.
|
|
243
|
+
file object. It may be omitted; then "puts path" is assumed, or
|
|
244
|
+
"puts cpath" in case the output is a terminal.
|
|
225
245
|
|
|
226
|
-
Default sort order is
|
|
246
|
+
Default sort order is by name.
|
|
227
247
|
EOT
|
|
228
248
|
end
|
|
229
249
|
|
|
@@ -246,7 +266,7 @@ module RbFind
|
|
|
246
266
|
$ rbfind -d -m3 -- /mnt/data
|
|
247
267
|
$ rbfind 'filesize > 10.MiB and colsep size.to_hib, path'
|
|
248
268
|
|
|
249
|
-
$ rbfind -
|
|
269
|
+
$ rbfind -U "name =~ /^\.*/ ; $'.downcase"
|
|
250
270
|
$ rbfind -B '$s=0' -E 'puts $s.to_h' 'filesize {|s|$s+=s}'
|
|
251
271
|
$ rbfind 'puts path if ext == ".rb"'
|
|
252
272
|
$ rbfind -p 'ext == ".rb"'
|
|
@@ -345,7 +365,7 @@ module RbFind
|
|
|
345
365
|
|
|
346
366
|
def show
|
|
347
367
|
puts "arguments:"
|
|
348
|
-
@args.each { |a| puts_val a }.any?
|
|
368
|
+
@args.each { |a| puts_val a }.any? or puts_val "(none)"
|
|
349
369
|
puts "parameters:"
|
|
350
370
|
@params.each { |k,v| puts_val k, "=", v }.any? or puts_val "(none)"
|
|
351
371
|
puts "block:"
|
|
@@ -447,8 +467,9 @@ class Integer
|
|
|
447
467
|
# convenient formatting, right justification
|
|
448
468
|
def method_missing sym, *args
|
|
449
469
|
case sym.to_s # .to_s for Ruby 1.8
|
|
450
|
-
when /\
|
|
451
|
-
|
|
470
|
+
when /\Aw(\d+)/ then "%#{$1}d" % self
|
|
471
|
+
when /\Aw_(\d+)/ then to_g.rjust $1.to_i
|
|
472
|
+
else super
|
|
452
473
|
end
|
|
453
474
|
end
|
|
454
475
|
end
|
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.8.2".freeze
|
|
12
12
|
|
|
13
13
|
=begin rdoc
|
|
14
14
|
|
|
@@ -270,14 +270,16 @@ Sort without case sensitivity and preceding dot:
|
|
|
270
270
|
|
|
271
271
|
private
|
|
272
272
|
|
|
273
|
-
Params = Struct.new :max_depth, :depth_first, :follow,
|
|
274
|
-
:sort, :reverse, :error, :block
|
|
273
|
+
Params = Struct.new :max_depth, :args_depth, :depth_first, :follow,
|
|
274
|
+
:sort, :dirs, :reverse, :error, :block
|
|
275
275
|
|
|
276
|
-
def initialize max_depth: nil, depth_first: nil, follow: nil,
|
|
277
|
-
sort: true, reverse: false, error: nil, &block
|
|
278
|
-
@params = Params.new max_depth, depth_first, follow,
|
|
279
|
-
(sort_parser sort), reverse, error, block
|
|
280
|
-
@start
|
|
276
|
+
def initialize max_depth: nil, args_depth: false, depth_first: nil, follow: nil,
|
|
277
|
+
sort: true, dirs: false, reverse: false, error: nil, &block
|
|
278
|
+
@params = Params.new max_depth, args_depth, depth_first, follow,
|
|
279
|
+
(sort_parser sort), dirs, reverse, error, block
|
|
280
|
+
@start = Time.instance_eval { @start = Time.now }
|
|
281
|
+
Time.instance_eval { @start = Time.now }
|
|
282
|
+
@count, @depth = 0, 0
|
|
281
283
|
end
|
|
282
284
|
|
|
283
285
|
def sort_parser st
|
|
@@ -297,13 +299,12 @@ Sort without case sensitivity and preceding dot:
|
|
|
297
299
|
if args.empty? then
|
|
298
300
|
visit_dir Dir::CUR_DIR
|
|
299
301
|
else
|
|
300
|
-
args.
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
302
|
+
list = args.map { |base| Entry.new base, self }
|
|
303
|
+
list.select! { |e| handle_error do e.stat end }
|
|
304
|
+
sort_entries list
|
|
305
|
+
step_depth_args do
|
|
306
|
+
list.each { |e| enter e }
|
|
307
|
+
end
|
|
307
308
|
end
|
|
308
309
|
end
|
|
309
310
|
|
|
@@ -313,34 +314,62 @@ Sort without case sensitivity and preceding dot:
|
|
|
313
314
|
|
|
314
315
|
private
|
|
315
316
|
|
|
317
|
+
def step_depth
|
|
318
|
+
@depth += 1
|
|
319
|
+
yield
|
|
320
|
+
ensure
|
|
321
|
+
@depth -= 1
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
def step_depth_args
|
|
325
|
+
if @params[ :args_depth] then
|
|
326
|
+
step_depth do
|
|
327
|
+
yield
|
|
328
|
+
end
|
|
329
|
+
else
|
|
330
|
+
yield
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
|
|
316
334
|
def enter elem
|
|
317
335
|
c_, @current = @current, elem
|
|
318
336
|
@count += 1
|
|
319
|
-
|
|
337
|
+
if @params.depth_first then
|
|
338
|
+
enter_dir
|
|
339
|
+
begin
|
|
340
|
+
call_block
|
|
341
|
+
rescue Prune
|
|
342
|
+
handle_error do
|
|
343
|
+
raise "#{self.class}: prune with :depth_first is pointless."
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
else
|
|
347
|
+
begin
|
|
348
|
+
call_block
|
|
349
|
+
enter_dir if @current.path
|
|
350
|
+
rescue Prune
|
|
351
|
+
end
|
|
352
|
+
end
|
|
320
353
|
ensure
|
|
321
354
|
@current = c_
|
|
322
355
|
end
|
|
323
356
|
|
|
324
357
|
def visit_dir dir
|
|
325
|
-
return if @params.max_depth and @params.max_depth
|
|
326
|
-
list = (Dir.new dir).children
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
list.reverse! if @params.reverse
|
|
330
|
-
begin
|
|
331
|
-
@depth += 1
|
|
358
|
+
return if @params.max_depth and @params.max_depth <= @depth
|
|
359
|
+
list = (Dir.new dir).children.map { |f| Entry.new f, self }
|
|
360
|
+
sort_entries list
|
|
361
|
+
step_depth do
|
|
332
362
|
list.each { |e| enter e }
|
|
333
|
-
ensure
|
|
334
|
-
@depth -= 1
|
|
335
363
|
end
|
|
336
364
|
end
|
|
337
365
|
|
|
338
|
-
def
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
366
|
+
def sort_entries list
|
|
367
|
+
@params.sort.call list
|
|
368
|
+
list.reverse! if @params.reverse
|
|
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!
|
|
344
373
|
end
|
|
345
374
|
end
|
|
346
375
|
|
|
@@ -361,9 +390,7 @@ Sort without case sensitivity and preceding dot:
|
|
|
361
390
|
@current.instance_eval &@params.block
|
|
362
391
|
rescue Done
|
|
363
392
|
end
|
|
364
|
-
@current.path
|
|
365
393
|
end
|
|
366
|
-
rescue Prune
|
|
367
394
|
end
|
|
368
395
|
|
|
369
396
|
def handle_error
|
data/lib/rbfind/humansiz.rb
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
=begin rdoc
|
|
7
7
|
|
|
8
|
-
Human readable sizes
|
|
8
|
+
Human readable sizes and times.
|
|
9
9
|
|
|
10
10
|
Examples:
|
|
11
11
|
|
|
@@ -136,12 +136,23 @@ class Time
|
|
|
136
136
|
# file.stat.mtime.lsish #=> " 1. Apr 2008 "
|
|
137
137
|
#
|
|
138
138
|
def lsish
|
|
139
|
-
strftime "
|
|
140
|
-
(year == Time.now.year ? "%H:%M:%S" : "%Y ")
|
|
139
|
+
strftime "%e. %b " + (year == Time.start.year ? "%H:%M:%S" : "%Y ")
|
|
141
140
|
end
|
|
142
141
|
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
def long
|
|
143
|
+
s = Time.start
|
|
144
|
+
if year == s.year && month == s.month && day == s.day then
|
|
145
|
+
strftime "==%H:%M:%S"
|
|
146
|
+
else
|
|
147
|
+
strftime "%Y-%m-%d"
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
class <<self
|
|
152
|
+
def start
|
|
153
|
+
@start ||= Time.now
|
|
154
|
+
end
|
|
155
|
+
end
|
|
145
156
|
|
|
146
157
|
end
|
|
147
158
|
|
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:
|
|
4
|
+
version: 2.8.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bertram Scharpf
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |
|
|
14
14
|
A replacement for the standard UNIX command find.
|