rbfind 2.5 → 2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rbfind +28 -13
  3. data/lib/rbfind.rb +10 -8
  4. data/lib/rbfind/humansiz.rb +16 -5
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bee921838a5b4d93f5483295e8c7e6b263e144e8d52e5ca53a464a222a5d055
4
- data.tar.gz: 03f0b19f70747dbb152011ecc8f414d99764ad9052c82f9b0b1715939fb7a3dd
3
+ metadata.gz: f0a448408396d2339b4aa0656dfeb579c6533373623ca9e6cb0e4b48812e2b03
4
+ data.tar.gz: d71f32510fdc92315c7f5aaa16d08560d6bc6b1d9515af85913f3c4a4f42e6ba
5
5
  SHA512:
6
- metadata.gz: 3de28232b6d9b842ced7ff2880e4d80938c194c13c93fd6a69e5265d3f6999276129bc1469eae62a121776222d27836c95cc208ae2d656080875345d342d471e
7
- data.tar.gz: d979151e81e3eaf660304c2072550f857957e9c08c4da74af67afc5d23e498021b546c33920ba20099fcb2248a2a621eccf51b9732b34212a1273188ec4d6c73
6
+ metadata.gz: bab39e437deaa7cf9d4e283f83c5ee354c3f28b4ed7159b90adfdcc7210c2dfce80593cfadcceb3c0702c4641c93b66b4fd2e4351deccd62adb9267754aaf588
7
+ data.tar.gz: 44adde8bccbb1f840187bb9973a7e835d098f05c715fa22cf493a06fa8c00bc5bdbdb7e0d5da77db925034f3315f16148fd7431ed8b745febaeaadda0d5fd560
data/bin/rbfind CHANGED
@@ -33,13 +33,17 @@ module RbFind
33
33
  [ %w(--depth -d), nil, "yield directory after its contents"],
34
34
  [ %w(--maxdepth -m), :num, "maxium step depth"],
35
35
  [ %w(--follow -y), nil, "follow symbolic links"],
36
- [ %w(--nosort -S), nil, "unsorted"],
36
+ [ %w(--nosort -U), nil, "unsorted"],
37
37
  [ %w(--sort-by -s), :str, "sort expression"],
38
38
  [ %w(--reverse -R), nil, "reverse the sort"],
39
+ [ %w(--time -t), nil, "sort by time, newest first"],
40
+ [ %w(--size -S), nil, "sort by size, largest first"],
41
+ [ %w(--dirs -F), nil, "sort directories before files"],
39
42
  [ %w(--require -r), :rb, "require library"],
40
43
  [ %w(--puts-path -p), nil, "do 'puts path/cpath' on true block"],
41
44
  [ %w(--ls-l -P), nil, "do 'ls -l' style output on true block"],
42
- [ %w(--wider -+), nil, "widen fields in long output format (--ls-l)"],
45
+ [ %w(--long -Q), nil, "alternate long format on true block"],
46
+ [ %w(--wider -+), nil, "widen fields in long output format"],
43
47
  [ %w(--slash -/), nil, "append a slash to directory names"],
44
48
  [ %w(--lines -l), :blk, "surround block by 'lines { |$_,$.| ... }'"],
45
49
  [ %w(--reallines -L), :blk, "same as -l but stop at any null character"],
@@ -52,6 +56,7 @@ module RbFind
52
56
  [ %w(--demand -D), :rgx, "skip all filenames but these"],
53
57
  [ %w(--ext -e), :lst, "skip all filename extensions but these"],
54
58
  [ %w(--visible -I), nil, "skip all hidden (starting with .dot)"],
59
+ [ %w(--all -a), nil, "all, including hidden (starting with .dot)"],
55
60
  [ %w(--nodirs -N), nil, "skip directories"],
56
61
  [ %w(--begin -B), :blk, "eval block before begin"],
57
62
  [ %w(--end -E), :blk, "eval block after end"],
@@ -81,12 +86,16 @@ module RbFind
81
86
  when '--maxdepth' then @params[ :max_depth] = arg.to_i
82
87
  when '--follow' then @params[ :follow] = true
83
88
  when '--nosort' then @params[ :sort] = false
84
- when '--sort-by' then @params[ :sort] = instance_eval "proc { |n| #{arg} }"
89
+ when '--sort-by' then @params[ :sort] = instance_eval "proc { #{arg} }"
90
+ when '--time' then @params[ :sort] = proc { mtime } ; @params[ :reverse] = true
91
+ when '--size' then @params[ :sort] = proc { size } ; @params[ :reverse] = true
92
+ when '--dirs' then @params[ :dirs] = true
85
93
  when '--reverse' then @params[ :reverse] = true
86
94
  when '--require' then require arg
87
95
  when '--puts-path' then @puts = true
88
- when '--ls-l' then @puts = true ; @wd = 6
89
- when '--wider' then @wd = @wd ? @wd.succ : 4
96
+ when '--ls-l' then @puts = :ls ; @wds = 6 ; @wd = 6
97
+ when '--long' then @puts = :alt ; @wds = 7 ; @wd = 4
98
+ when '--wider' then @wd and @wd += 2.succ ; @wds and @wds += @puts == :alt ? 4 : 3
90
99
  when '--slash' then @slash = true
91
100
  when '--lines' then @lines = :plain ; @block = arg
92
101
  when '--reallines' then @lines = :plain ; @real = true ; @block = arg
@@ -99,6 +108,7 @@ module RbFind
99
108
  when '--demand' then @demand = arg
100
109
  when '--ext' then @ext = arg
101
110
  when '--visible' then @visible = true
111
+ when '--all' then @visible = false
102
112
  when '--nodirs' then @nodirs = true
103
113
  when '--begin' then @blkbegin = arg
104
114
  when '--end' then @blkend = arg
@@ -150,11 +160,15 @@ module RbFind
150
160
  end
151
161
  if @puts then
152
162
  @block = "( #@block ) and "
153
- @block << if @wd then
154
- "spcsep stype+modes, user.w#@wd, group.w#@wd, size.w#@wd, " +
155
- "mtime.lsish, #{opath} + #{co ? 'carrow' : 'arrow'}.to_s"
156
- else
157
- "puts #{opath}"
163
+ @block << case @puts
164
+ when :alt then
165
+ "spcsep stype+modes, user!.w#@wd, group!.w#@wd, size.w_#@wds, " +
166
+ "mtime.long, #{opath} + #{co ? 'carrow' : 'arrow'}.to_s"
167
+ when :ls then
168
+ "spcsep stype+modes, user.w#@wd, group.w#@wd, size.w#@wds, " +
169
+ "mtime.lsish, #{opath} + #{co ? 'carrow' : 'arrow'}.to_s"
170
+ else
171
+ "puts #{opath}"
158
172
  end
159
173
  end
160
174
 
@@ -246,7 +260,7 @@ module RbFind
246
260
  $ rbfind -d -m3 -- /mnt/data
247
261
  $ rbfind 'filesize > 10.MiB and colsep size.to_hib, path'
248
262
 
249
- $ rbfind -S "name =~ /^\.*/ ; $'.downcase"
263
+ $ rbfind -U "name =~ /^\.*/ ; $'.downcase"
250
264
  $ rbfind -B '$s=0' -E 'puts $s.to_h' 'filesize {|s|$s+=s}'
251
265
  $ rbfind 'puts path if ext == ".rb"'
252
266
  $ rbfind -p 'ext == ".rb"'
@@ -447,8 +461,9 @@ class Integer
447
461
  # convenient formatting, right justification
448
462
  def method_missing sym, *args
449
463
  case sym.to_s # .to_s for Ruby 1.8
450
- when /\Aw_?(\d+)/ then "%#{$1}d" % self
451
- else super
464
+ when /\Aw(\d+)/ then "%#{$1}d" % self
465
+ when /\Aw_(\d+)/ then to_g.rjust $1.to_i
466
+ else super
452
467
  end
453
468
  end
454
469
  end
data/lib/rbfind.rb CHANGED
@@ -8,7 +8,7 @@ require "rbfind/csv"
8
8
 
9
9
  module RbFind
10
10
 
11
- VERSION = "2.5".freeze
11
+ VERSION = "2.6".freeze
12
12
 
13
13
  =begin rdoc
14
14
 
@@ -271,13 +271,15 @@ Sort without case sensitivity and preceding dot:
271
271
  private
272
272
 
273
273
  Params = Struct.new :max_depth, :depth_first, :follow,
274
- :sort, :reverse, :error, :block
274
+ :sort, :dirs, :reverse, :error, :block
275
275
 
276
276
  def initialize max_depth: nil, depth_first: nil, follow: nil,
277
- sort: true, reverse: false, error: nil, &block
277
+ sort: true, dirs: false, reverse: false, error: nil, &block
278
278
  @params = Params.new max_depth, depth_first, follow,
279
- (sort_parser sort), reverse, error, block
280
- @start, @count, @depth = Time.now, 0, 0
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
@@ -323,10 +325,10 @@ Sort without case sensitivity and preceding dot:
323
325
 
324
326
  def visit_dir dir
325
327
  return if @params.max_depth and @params.max_depth == @depth
326
- list = (Dir.new dir).children
327
- list = list.map { |f| Entry.new f, self }
328
+ list = (Dir.new dir).children.map { |f| Entry.new f, self }
328
329
  @params.sort.call list
329
- list.reverse! if @params.reverse
330
+ @params.reverse and list.reverse!
331
+ @params.dirs and list = list.partition { |e| e.rstat.directory? }.flatten
330
332
  begin
331
333
  @depth += 1
332
334
  list.each { |e| enter e }
@@ -5,7 +5,7 @@
5
5
 
6
6
  =begin rdoc
7
7
 
8
- Human readable sizes, times, and modes.
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 "#{PERC_DAY}. %b " +
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
- # Windows has no "%e".
144
- PERC_DAY = Time.now.strftime("%e") =~ /\d/ ? "%e" : "%d" # :nodoc:
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.5'
4
+ version: '2.6'
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-02-24 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  A replacement for the standard UNIX command find.