rbfind 2.3.1 → 2.8
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 +58 -20
- data/lib/rbfind.rb +132 -102
- 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: 530e1d61cf675c858a06f62e62cbfe5cfa7b1492ec1ef9c77e293f7f0bb0b83d
|
|
4
|
+
data.tar.gz: '004834c6e324c296e0b4185910c8a1a70179ef90fbaeee0b262a8816d8e762af'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e6b7d8ce6bd4d81824705b4dd311383888ff6fa02dc0a6fc94c7b307432fd7cc1b17643b75a53e7917796def4c91fd6f7243424778c64ab9d1932b5575852e04
|
|
7
|
+
data.tar.gz: eb837f165e31d40ed2323bbcdf2344adf32a113d1520d6dbb83c844d17f4487b44adfe997189e17734b413c368a93a71e6053a0ae697212652bd2ab578e1a620
|
data/bin/rbfind
CHANGED
|
@@ -32,14 +32,20 @@ module RbFind
|
|
|
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
34
|
[ %w(--maxdepth -m), :num, "maxium step depth"],
|
|
35
|
+
[ %w(--anydepth -M), nil, "no maxium step depth"],
|
|
35
36
|
[ %w(--follow -y), nil, "follow symbolic links"],
|
|
36
|
-
[ %w(--nosort -
|
|
37
|
-
[ %w(--sort-by -s), :str, "sort expression
|
|
38
|
-
[ %w(--reverse -R),
|
|
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"],
|
|
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"],
|
|
@@ -48,14 +54,15 @@ module RbFind
|
|
|
48
54
|
[ %w(--binary -b), nil, "grep even binary files"],
|
|
49
55
|
[ %w(--no-vcs -C), nil, "prune version control dirs (CVS/.svn/.git)"],
|
|
50
56
|
[ %w(--no-swap -W), nil, "ignore Vim swapfiles"],
|
|
51
|
-
[ %w(--skip -k), :
|
|
52
|
-
[ %w(--demand -D), :
|
|
57
|
+
[ %w(--skip -k), :rgx, "filenames to skip"],
|
|
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"],
|
|
58
|
-
[ %w(--file -f), :
|
|
65
|
+
[ %w(--file -f), :nam, "read block expression from file"],
|
|
59
66
|
[ %w(--encoding -K), :str, "encoding extern[:intern] (same as ruby -E)"],
|
|
60
67
|
]
|
|
61
68
|
|
|
@@ -79,14 +86,20 @@ module RbFind
|
|
|
79
86
|
when '--colored' then @color = true
|
|
80
87
|
when '--depth' then @params[ :depth_first] = true
|
|
81
88
|
when '--maxdepth' then @params[ :max_depth] = arg.to_i
|
|
89
|
+
when '--anydepth' then @params[ :max_depth] = nil
|
|
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
|
|
@@ -142,7 +156,7 @@ module RbFind
|
|
|
142
156
|
@binary or @block = "not binary? and (#@block)"
|
|
143
157
|
|
|
144
158
|
else
|
|
145
|
-
@block ||= if @args.last and not (File.
|
|
159
|
+
@block ||= if @args.last and not (File.lstat @args.last rescue false) then
|
|
146
160
|
@args.pop.dup
|
|
147
161
|
else
|
|
148
162
|
@puts ||= true
|
|
@@ -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
|
|
|
@@ -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"'
|
|
@@ -338,6 +358,9 @@ module RbFind
|
|
|
338
358
|
error_handle do
|
|
339
359
|
eval @blkbegin if @blkbegin
|
|
340
360
|
b = @block
|
|
361
|
+
if not @args.empty? and @params[ :max_depth] then
|
|
362
|
+
@params[ :max_depth] -= 1
|
|
363
|
+
end
|
|
341
364
|
Walk.run *@args, **@params do instance_eval b end
|
|
342
365
|
eval @blkend if @blkend
|
|
343
366
|
end
|
|
@@ -345,7 +368,7 @@ module RbFind
|
|
|
345
368
|
|
|
346
369
|
def show
|
|
347
370
|
puts "arguments:"
|
|
348
|
-
@args.each { |a| puts_val a }.any?
|
|
371
|
+
@args.each { |a| puts_val a }.any? or puts_val "(none)"
|
|
349
372
|
puts "parameters:"
|
|
350
373
|
@params.each { |k,v| puts_val k, "=", v }.any? or puts_val "(none)"
|
|
351
374
|
puts "block:"
|
|
@@ -447,8 +470,9 @@ class Integer
|
|
|
447
470
|
# convenient formatting, right justification
|
|
448
471
|
def method_missing sym, *args
|
|
449
472
|
case sym.to_s # .to_s for Ruby 1.8
|
|
450
|
-
when /\
|
|
451
|
-
|
|
473
|
+
when /\Aw(\d+)/ then "%#{$1}d" % self
|
|
474
|
+
when /\Aw_(\d+)/ then to_g.rjust $1.to_i
|
|
475
|
+
else super
|
|
452
476
|
end
|
|
453
477
|
end
|
|
454
478
|
end
|
|
@@ -483,6 +507,20 @@ class NilClass
|
|
|
483
507
|
end
|
|
484
508
|
end
|
|
485
509
|
|
|
510
|
+
class TrueClass
|
|
511
|
+
def <=> oth
|
|
512
|
+
oth == true ? 0 : oth == false ? 1 : nil
|
|
513
|
+
end
|
|
514
|
+
include Enumerable
|
|
515
|
+
end
|
|
516
|
+
|
|
517
|
+
class FalseClass
|
|
518
|
+
def <=> oth
|
|
519
|
+
oth == false ? 0 : oth == true ? -1 : nil
|
|
520
|
+
end
|
|
521
|
+
include Enumerable
|
|
522
|
+
end
|
|
523
|
+
|
|
486
524
|
class Proc
|
|
487
525
|
def to_s
|
|
488
526
|
"#<%s:0x%08x>" % [ self.class, object_id]
|
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".freeze
|
|
12
12
|
|
|
13
13
|
=begin rdoc
|
|
14
14
|
|
|
@@ -241,7 +241,7 @@ Reverse sort:
|
|
|
241
241
|
|
|
242
242
|
Sort without case sensitivity and preceding dot:
|
|
243
243
|
|
|
244
|
-
s = proc {
|
|
244
|
+
s = proc { name =~ /^\.?/ ; $'.downcase }
|
|
245
245
|
RbFind.run sort: s do
|
|
246
246
|
puts path
|
|
247
247
|
end
|
|
@@ -270,141 +270,119 @@ Sort without case sensitivity and preceding dot:
|
|
|
270
270
|
|
|
271
271
|
private
|
|
272
272
|
|
|
273
|
-
|
|
274
|
-
sort:
|
|
275
|
-
@max_depth = max_depth
|
|
276
|
-
@depth_first = depth_first
|
|
277
|
-
@follow = follow
|
|
278
|
-
@sort = sort_parser sort, reverse
|
|
279
|
-
@error = error
|
|
280
|
-
@block = block
|
|
281
|
-
|
|
282
|
-
ostat = $stdout.stat
|
|
283
|
-
@ostat = ostat if ostat.file?
|
|
284
|
-
|
|
285
|
-
@wd, @start, @count = Dir.getwd, Time.now, 0
|
|
286
|
-
end
|
|
273
|
+
Params = Struct.new :max_depth, :depth_first, :follow,
|
|
274
|
+
:sort, :dirs, :reverse, :error, :block
|
|
287
275
|
|
|
288
|
-
def
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
276
|
+
def initialize max_depth: nil, depth_first: nil, follow: nil,
|
|
277
|
+
sort: true, dirs: false, reverse: false, error: nil, &block
|
|
278
|
+
@params = Params.new max_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
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
def sort_parser st
|
|
286
|
+
case st
|
|
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 } }
|
|
293
291
|
end
|
|
294
|
-
rev ? proc { |l| r.call l ; l.reverse! } : r
|
|
295
292
|
end
|
|
296
293
|
|
|
297
294
|
public
|
|
298
295
|
|
|
299
|
-
attr_reader :wd, :start, :count, :depth
|
|
300
|
-
|
|
301
296
|
def run *args
|
|
302
|
-
@levels, @depth = [], 0
|
|
303
297
|
args.flatten!
|
|
304
298
|
args.compact!
|
|
305
299
|
if args.empty? then
|
|
306
300
|
visit_dir Dir::CUR_DIR
|
|
307
301
|
else
|
|
308
302
|
args.each { |base|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
visit_depth base
|
|
312
|
-
end
|
|
303
|
+
e = Entry.new base, self
|
|
304
|
+
enter e if handle_error do e.stat end
|
|
313
305
|
}
|
|
314
306
|
end
|
|
315
|
-
ensure
|
|
316
|
-
@levels = @depth = nil
|
|
317
307
|
end
|
|
318
308
|
|
|
319
|
-
|
|
309
|
+
attr_reader :start, :count
|
|
310
|
+
attr_reader :depth
|
|
311
|
+
attr_reader :current
|
|
320
312
|
|
|
321
|
-
|
|
322
|
-
(File.join @levels).freeze
|
|
323
|
-
end
|
|
313
|
+
private
|
|
324
314
|
|
|
325
|
-
def
|
|
315
|
+
def step_depth
|
|
326
316
|
@depth += 1
|
|
327
|
-
|
|
317
|
+
yield
|
|
328
318
|
ensure
|
|
329
319
|
@depth -= 1
|
|
330
320
|
end
|
|
331
321
|
|
|
332
|
-
def
|
|
333
|
-
@
|
|
334
|
-
|
|
335
|
-
if @depth_first then
|
|
322
|
+
def enter elem
|
|
323
|
+
c_, @current = @current, elem
|
|
324
|
+
@count += 1
|
|
325
|
+
if @params.depth_first then
|
|
336
326
|
enter_dir
|
|
337
|
-
|
|
327
|
+
begin
|
|
328
|
+
call_block
|
|
329
|
+
rescue Prune
|
|
330
|
+
handle_error do
|
|
331
|
+
raise "#{self.class}: prune with :depth_first is pointless."
|
|
332
|
+
end
|
|
333
|
+
end
|
|
338
334
|
else
|
|
339
|
-
|
|
335
|
+
begin
|
|
336
|
+
call_block
|
|
337
|
+
enter_dir if @current.path
|
|
338
|
+
rescue Prune
|
|
339
|
+
end
|
|
340
340
|
end
|
|
341
|
-
@count += 1
|
|
342
341
|
ensure
|
|
343
|
-
@
|
|
344
|
-
@levels.pop
|
|
342
|
+
@current = c_
|
|
345
343
|
end
|
|
346
344
|
|
|
347
|
-
def
|
|
348
|
-
return
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
true
|
|
357
|
-
end
|
|
345
|
+
def visit_dir dir
|
|
346
|
+
return if @params.max_depth and @params.max_depth == @depth
|
|
347
|
+
list = (Dir.new dir).children.map { |f| Entry.new f, self }
|
|
348
|
+
@params.sort.call list
|
|
349
|
+
list.reverse! if @params.reverse
|
|
350
|
+
if @params.dirs then
|
|
351
|
+
list = list.partition { |e| e.rstat.directory? rescue nil }
|
|
352
|
+
list.reverse! if @params.depth_first
|
|
353
|
+
list.flatten!
|
|
358
354
|
end
|
|
359
|
-
|
|
360
|
-
|
|
355
|
+
step_depth do
|
|
356
|
+
list.each { |e| enter e }
|
|
361
357
|
end
|
|
362
358
|
end
|
|
363
359
|
|
|
364
|
-
def
|
|
365
|
-
return
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
360
|
+
def enter_dir
|
|
361
|
+
return unless @current.stat.directory? || (@params.follow &&
|
|
362
|
+
@current.symlink? && @current.rstat.directory?)
|
|
363
|
+
handle_error do
|
|
364
|
+
@current.cyclic? and
|
|
365
|
+
raise "Cyclic recursion in #{@current.path}"
|
|
366
|
+
visit_dir @current.path
|
|
367
|
+
end
|
|
370
368
|
end
|
|
371
369
|
|
|
372
370
|
def call_block
|
|
373
|
-
e = Entry.new @levels.last, @path, self
|
|
374
371
|
handle_error do
|
|
375
|
-
$_, $. = e.name, count
|
|
376
372
|
begin
|
|
377
|
-
|
|
373
|
+
$_, $. = @current.name, @count
|
|
374
|
+
@current.instance_eval &@params.block
|
|
378
375
|
rescue Done
|
|
379
376
|
end
|
|
380
|
-
if !(e.name.equal? @levels.last) && e.name != @levels.last then
|
|
381
|
-
if e.name then
|
|
382
|
-
e.name == (File.basename e.name) or
|
|
383
|
-
raise "#{self.class}: rename to `#{e.name}' may not be a path."
|
|
384
|
-
e.name.freeze
|
|
385
|
-
@levels.pop
|
|
386
|
-
@levels.push e.name
|
|
387
|
-
p, @path = @path, join_path
|
|
388
|
-
File.rename p, @path
|
|
389
|
-
else
|
|
390
|
-
if e.dir? then
|
|
391
|
-
Dir.rmdir @path
|
|
392
|
-
else
|
|
393
|
-
File.unlink @path
|
|
394
|
-
end
|
|
395
|
-
end
|
|
396
|
-
end
|
|
397
|
-
true
|
|
398
377
|
end
|
|
399
|
-
rescue Prune
|
|
400
378
|
end
|
|
401
379
|
|
|
402
380
|
def handle_error
|
|
403
381
|
yield
|
|
404
382
|
rescue
|
|
405
|
-
case @error
|
|
406
|
-
when Proc then @error.call
|
|
407
|
-
when String then instance_eval @error
|
|
383
|
+
case @params.error
|
|
384
|
+
when Proc then @params.error.call
|
|
385
|
+
when String then instance_eval @params.error
|
|
408
386
|
else raise
|
|
409
387
|
end
|
|
410
388
|
nil
|
|
@@ -417,21 +395,35 @@ Sort without case sensitivity and preceding dot:
|
|
|
417
395
|
|
|
418
396
|
attr_reader :path, :name
|
|
419
397
|
|
|
420
|
-
def initialize
|
|
421
|
-
@
|
|
398
|
+
def initialize filename, walk
|
|
399
|
+
@walk = walk
|
|
400
|
+
@prev, @name = walk.current, filename.dup.freeze
|
|
401
|
+
@path = join_path @name
|
|
422
402
|
end
|
|
423
403
|
|
|
404
|
+
protected
|
|
405
|
+
attr_reader :prev
|
|
406
|
+
private
|
|
407
|
+
def join_path name
|
|
408
|
+
@prev ? (File.join @prev.path, name).freeze : name
|
|
409
|
+
end
|
|
410
|
+
def reset
|
|
411
|
+
@fullpath = @stat = @rstat = @ostat = @colors = nil
|
|
412
|
+
end
|
|
413
|
+
public
|
|
414
|
+
|
|
415
|
+
def count ; @walk.count ; end
|
|
424
416
|
def depth ; @walk.depth ; end
|
|
425
417
|
def now ; @walk.start ; end
|
|
426
418
|
|
|
427
|
-
def fullpath ; @fullpath ||= File.absolute_path @path
|
|
419
|
+
def fullpath ; @fullpath ||= File.absolute_path @path ; end
|
|
428
420
|
|
|
429
421
|
def stat ; @stat ||= File.lstat @path ; end
|
|
430
422
|
def rstat ; @rstat ||= File.stat @path ; end
|
|
431
423
|
|
|
432
424
|
|
|
433
425
|
private
|
|
434
|
-
def append_slash s ;
|
|
426
|
+
def append_slash s ; directory? ? (File.join s, "") : s ; end
|
|
435
427
|
public
|
|
436
428
|
|
|
437
429
|
def path! ; append_slash path ; end
|
|
@@ -461,7 +453,23 @@ Sort without case sensitivity and preceding dot:
|
|
|
461
453
|
end
|
|
462
454
|
public
|
|
463
455
|
|
|
464
|
-
def
|
|
456
|
+
def directory? ; stat.directory? ; end
|
|
457
|
+
alias dir? directory?
|
|
458
|
+
|
|
459
|
+
def symlink? ; stat.symlink? ; end
|
|
460
|
+
|
|
461
|
+
def cyclic?
|
|
462
|
+
e = self
|
|
463
|
+
loop do
|
|
464
|
+
e = e.prev
|
|
465
|
+
e or break
|
|
466
|
+
if File.identical? e.path, @path then
|
|
467
|
+
return true
|
|
468
|
+
end
|
|
469
|
+
end
|
|
470
|
+
false
|
|
471
|
+
end
|
|
472
|
+
|
|
465
473
|
|
|
466
474
|
def aage ; @walk.start - stat.atime ; end
|
|
467
475
|
def mage ; @walk.start - stat.mtime ; end
|
|
@@ -516,10 +524,10 @@ Sort without case sensitivity and preceding dot:
|
|
|
516
524
|
end
|
|
517
525
|
|
|
518
526
|
|
|
519
|
-
def readlink ; File.readlink @path if
|
|
527
|
+
def readlink ; File.readlink @path if symlink? ; end
|
|
520
528
|
|
|
521
529
|
def broken_link?
|
|
522
|
-
return unless
|
|
530
|
+
return unless symlink?
|
|
523
531
|
rstat
|
|
524
532
|
false
|
|
525
533
|
rescue
|
|
@@ -529,7 +537,7 @@ Sort without case sensitivity and preceding dot:
|
|
|
529
537
|
|
|
530
538
|
ARROW = " -> "
|
|
531
539
|
def arrow
|
|
532
|
-
ARROW + (File.readlink @path) if
|
|
540
|
+
ARROW + (File.readlink @path) if symlink?
|
|
533
541
|
end
|
|
534
542
|
|
|
535
543
|
|
|
@@ -552,7 +560,11 @@ Sort without case sensitivity and preceding dot:
|
|
|
552
560
|
# Check whether a directory contains an entry.
|
|
553
561
|
#
|
|
554
562
|
def contains? name
|
|
555
|
-
|
|
563
|
+
p = File.join @path, name
|
|
564
|
+
File.lstat p
|
|
565
|
+
true
|
|
566
|
+
rescue
|
|
567
|
+
false
|
|
556
568
|
end
|
|
557
569
|
|
|
558
570
|
# :call-seq:
|
|
@@ -580,7 +592,8 @@ Sort without case sensitivity and preceding dot:
|
|
|
580
592
|
# nothing will be done.
|
|
581
593
|
#
|
|
582
594
|
def open &block
|
|
583
|
-
@ostat
|
|
595
|
+
@ostat ||= $stdout.stat
|
|
596
|
+
@ostat.identical? @path and
|
|
584
597
|
raise "Refusing to open output file."
|
|
585
598
|
File.open @path, &block if file?
|
|
586
599
|
end
|
|
@@ -690,10 +703,27 @@ Sort without case sensitivity and preceding dot:
|
|
|
690
703
|
include Csv
|
|
691
704
|
|
|
692
705
|
|
|
693
|
-
def rename newname
|
|
706
|
+
def rename newname
|
|
707
|
+
@name = newname
|
|
708
|
+
newname == (File.basename newname) or
|
|
709
|
+
raise "Rename to `#{newname}' may not be a path."
|
|
710
|
+
p = join_path newname
|
|
711
|
+
(File.exist? p) and raise "Rename to `#{p}` would overwrite."
|
|
712
|
+
File.rename @path, p
|
|
713
|
+
@name, @path = newname.dup.freeze, p
|
|
714
|
+
reset
|
|
715
|
+
end
|
|
694
716
|
alias mv rename
|
|
695
717
|
|
|
696
|
-
def rm
|
|
718
|
+
def rm
|
|
719
|
+
if directory? then
|
|
720
|
+
Dir.rmdir @path
|
|
721
|
+
else
|
|
722
|
+
File.unlink @path
|
|
723
|
+
end
|
|
724
|
+
@name = @path = nil
|
|
725
|
+
reset
|
|
726
|
+
end
|
|
697
727
|
|
|
698
728
|
|
|
699
729
|
def cname ; color name ; end
|
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: 2.
|
|
4
|
+
version: '2.8'
|
|
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: 2021-03-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |
|
|
14
14
|
A replacement for the standard UNIX command find.
|