rbfind 2.0.1 → 2.3

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: 5a6e7b3de72cc2efdb3033593f8ffac176da6dab3395d68594570d08c3992249
4
- data.tar.gz: 36f03f0b41bd1180429bd527f0fa7f6a8f8e2897c3f99569fbc6250f3e358baf
3
+ metadata.gz: 0655e863af78b2081d7306e8823694ef7ad5c48625dbdd9c7f0f75fb8a85d4d7
4
+ data.tar.gz: 0ef05d8082c2487d7079176ea8373f31e392d41eb1dd269555c47832ff313689
5
5
  SHA512:
6
- metadata.gz: b30427e248f24b028eb554b5c5672d96695f7fdec4c87e3ae39343671702c89e02664a78ac6bbc40f101baa348fbebc67c9a5e564f8694d27e9d53b1bc7cd103
7
- data.tar.gz: 847dbf390ec156f619b06c1820e5df1ca4d51f89b8ebc7ae06f7a055d98bd734d74a7ae6d122e5c58d5eaa0ce183afba0a70db1856801d62bd413c49988ad6b4
6
+ metadata.gz: 915e2359d8bb0c7814c682f8247e71eb7db8742a8095c2cdbb44194252df0ba2636602443ca916055a3f260cece8de837118c565c76ca2bfb470dd2409749a94
7
+ data.tar.gz: f72fdc455e7ac5eba31060f3c96176f47985f7a4f41fd55d089dc78d7b713838365c5b949f537b7089b223829e63ac5ed64935af9a80a90639e31aa7ade67474
data/bin/rbfind CHANGED
@@ -37,7 +37,6 @@ module RbFind
37
37
  [ %w(--sort-by -s), :str, "sort expression ('n' is name)"],
38
38
  [ %w(--reverse -R), :str, "reverse sort"],
39
39
  [ %w(--require -r), :rb, "require library"],
40
- [ %w(--fileutils -U), nil, "include FileUtils module"],
41
40
  [ %w(--puts-path -p), nil, "do 'puts path/cpath' on true block"],
42
41
  [ %w(--ls-l -P), nil, "do 'ls -l' style output on true block"],
43
42
  [ %w(--wider -+), nil, "widen fields in long output format (--ls-l)"],
@@ -85,7 +84,6 @@ module RbFind
85
84
  when '--sort-by' then @params[ :sort] = instance_eval "proc { |n| #{arg} }"
86
85
  when '--reverse' then @params[ :reverse] = true
87
86
  when '--require' then require arg
88
- when '--fileutils' then require "fileutils" ; include FileUtils
89
87
  when '--puts-path' then @puts = true
90
88
  when '--ls-l' then @puts = true ; @wd = 6
91
89
  when '--wider' then @wd = @wd ? @wd.succ : 4
@@ -138,7 +136,7 @@ module RbFind
138
136
 
139
137
  when :grep then
140
138
  re = Regexp.new @block, @icase && Regexp::IGNORECASE
141
- @block = "grep #{re.inspect}"
139
+ @block = "grep %r#{re.inspect}"
142
140
  @block << ", true" if co
143
141
  @block << " ; $stdout.flush" unless $stdout.tty?
144
142
  @binary or @block = "not binary? and (#@block)"
@@ -371,6 +369,7 @@ module RbFind
371
369
  alias hidden hidden?
372
370
  alias visible visible?
373
371
  alias broken_link broken_link?
372
+ alias broken broken?
374
373
  alias dir dir?
375
374
  alias binary binary?
376
375
  alias bin bin?
@@ -8,7 +8,7 @@ require "rbfind/csv"
8
8
 
9
9
  module RbFind
10
10
 
11
- VERSION = "2.0.1".freeze
11
+ VERSION = "2.3".freeze
12
12
 
13
13
  =begin rdoc
14
14
 
@@ -119,6 +119,8 @@ Derivated from stat:
119
119
  csv sep, path, ... # separate by user-defined separator
120
120
 
121
121
  rename newname # rename, but leave it in the same directory
122
+ mv newname # dto.
123
+ rm # remove
122
124
 
123
125
 
124
126
  == Color support
@@ -374,16 +376,22 @@ Sort without case sensitivity and preceding dot:
374
376
  begin
375
377
  e.instance_eval &@block
376
378
  rescue Done
377
- ensure
378
- if !(e.name.equal? @levels.last) && e.name != @levels.last then
379
- p = @path
379
+ end
380
+ if !(e.name.equal? @levels.last) && e.name != @levels.last then
381
+ if e.name then
380
382
  e.name == (File.basename e.name) or
381
383
  raise "#{self.class}: rename to `#{e.name}' may not be a path."
382
384
  e.name.freeze
383
385
  @levels.pop
384
386
  @levels.push e.name
385
- @path = join_path
387
+ p, @path = @path, join_path
386
388
  File.rename p, @path
389
+ else
390
+ if e.dir? then
391
+ Dir.rmdir @path
392
+ else
393
+ File.unlink @path
394
+ end
387
395
  end
388
396
  end
389
397
  true
@@ -511,12 +519,13 @@ Sort without case sensitivity and preceding dot:
511
519
  def readlink ; File.readlink @path if stat.symlink? ; end
512
520
 
513
521
  def broken_link?
514
- return if stat.symlink?
522
+ return unless stat.symlink?
515
523
  rstat
516
524
  false
517
525
  rescue
518
526
  true
519
527
  end
528
+ alias broken? broken_link?
520
529
 
521
530
  ARROW = " -> "
522
531
  def arrow
@@ -682,7 +691,9 @@ Sort without case sensitivity and preceding dot:
682
691
 
683
692
 
684
693
  def rename newname ; @name = newname ; end
694
+ alias mv rename
685
695
 
696
+ def rm ; @name = nil ; end
686
697
 
687
698
 
688
699
  def cname ; color name ; end
@@ -83,6 +83,16 @@ class Numeric # sizes in bytes
83
83
  end
84
84
 
85
85
 
86
+ class Integer
87
+ def to_g
88
+ s = to_s
89
+ l = []
90
+ while (t = s.slice! /\d{1,3}\z/) do l.unshift t end
91
+ l.join "_"
92
+ end
93
+ end
94
+
95
+
86
96
  class Numeric
87
97
  "smhdw".each_char { |c|
88
98
  define_method c do Time.to_sec self, c end
@@ -9,18 +9,28 @@ module RbFind
9
9
 
10
10
  def initialize *heads
11
11
  heads.flatten!
12
- @heads = heads
12
+ @heads = heads.map { |h|
13
+ a = case h
14
+ when />\z/ then +1
15
+ when /\^\z/ then 0
16
+ when /<?\z/ then -1
17
+ end
18
+ [ $`, a]
19
+ }
13
20
  @rows = []
14
21
  end
15
22
 
16
- def spawn
17
- self.class.new *@heads
23
+ attr_reader :heads
24
+ protected :heads
25
+ def initialize_copy oth
26
+ @heads = oth.heads
27
+ @rows = []
18
28
  end
19
29
 
20
30
  def add *row
21
31
  row.flatten!
22
32
  n = @heads.size
23
- row[ 0, n] = row[ 0, n].map { |r| r.to_s }
33
+ row.map! { |r| break if n.zero? ; n -= 1 ; r.to_s }
24
34
  @rows.push row
25
35
  end
26
36
 
@@ -38,14 +48,14 @@ module RbFind
38
48
 
39
49
  def make_lines head: false
40
50
  rs = @rows
41
- rs.unshift heads_plain if head
51
+ rs.unshift @heads.map { |(h,a)| h } if head
42
52
  w = calc_widths
43
53
  rs.each { |r|
44
- j = (w.zip @heads, r).map { |v,h,c|
45
- case h
46
- when />\z/ then c.rjust v
47
- when /\^\z/ then c.center v
48
- when /<?\z/ then c.ljust v
54
+ j = (w.zip @heads, r).map { |v,(_,a),c|
55
+ case a
56
+ when -1 then c.ljust v
57
+ when 0 then c.center v
58
+ when +1 then c.rjust v
49
59
  end
50
60
  }
51
61
  l = j.join " "
@@ -59,14 +69,14 @@ module RbFind
59
69
  @html = ""
60
70
  tag :table, table, nl: 2 do
61
71
  tag :tr, row, nl: 1 do
62
- (@heads.zip heads_plain).each { |h,c|
63
- tag :td, c.downcase, align: (html_align h) do @html << c end
72
+ @heads.each { |(h,a)|
73
+ tag :td, h.downcase, align: a do @html << h end
64
74
  }
65
75
  end
66
76
  @rows.each { |r|
67
77
  tag :tr, table, nl: 1 do
68
- (@heads.zip heads_plain, r).each { |h,g,c|
69
- tag :td, g.downcase, align: (html_align h) do @html << c end
78
+ (@heads.zip r).each { |(g,a),c|
79
+ tag :td, g.downcase, align: a do @html << c end
70
80
  }
71
81
  end
72
82
  }
@@ -86,13 +96,9 @@ module RbFind
86
96
  w
87
97
  end
88
98
 
89
- def heads_plain
90
- @heads.map { |h| h.sub /\W\z/, "" }
91
- end
92
-
93
99
  def tag name, cls, nl: 0, align: nil
94
100
  @html << "<#{name}"
95
- @html << " style=\"text-align: " << align << ";\"" if align
101
+ @html << " style=\"text-align: " << (html_align align) << ";\"" if align
96
102
  @html << " class=\"" << cls << "\"" if cls
97
103
  @html << ">"
98
104
  @html << $/ if nl > 1
@@ -101,11 +107,11 @@ module RbFind
101
107
  @html << $/ if nl > 0
102
108
  end
103
109
 
104
- def html_align h
105
- case h
106
- when />/ then "right"
107
- when /\^/ then "center"
108
- when /<?/ then "left"
110
+ def html_align a
111
+ case a
112
+ when -1 then "left"
113
+ when 0 then "center"
114
+ when +1 then "right"
109
115
  end
110
116
  end
111
117
 
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.0.1
4
+ version: '2.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-18 00:00:00.000000000 Z
11
+ date: 2020-10-24 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.0.6
57
+ rubygems_version: 3.0.8
58
58
  signing_key:
59
59
  specification_version: 4
60
60
  summary: Ruby replacement for the standard Unix find tool