rbfind 2.0.2 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37699eab678876b60d10d42b360d2a3bdb4f1b47d950ee28077d2087d5f35d15
4
- data.tar.gz: 575d2eaeb4208087545448ae9627a9dbf8c652e068e88c3caad3707897a3a4da
3
+ metadata.gz: 28dcc78acea4b26243eb554d31b6df6e97e4ab0b382df6f0cc50382c5c6721cf
4
+ data.tar.gz: 8711486e4e567c6581849ac029c2f7b887f4dc707759e17ca52d7e4f45ffafa0
5
5
  SHA512:
6
- metadata.gz: 9027e94322984970d2aba116bd3e135395ab5fab025d36bc78796b7038057398e4fe10cc2917fd1872391be8250e609559d9c6d53c8af7cc2de6a664c4ad885c
7
- data.tar.gz: 9cc76b09a38a3212a67ddbf5d590247b672f1ed80fbfa36e9d4dfd5874f07119c57f0e76ee3c780cfe882eec02aa9d54c2567c5e2742aae12c27d88d5e6bfbbe
6
+ metadata.gz: 928d4d2718225a08935c7590c40bd6e917cc0e520f44c657c8e9bf0d496a0b7712452408035f9355992dffb26011156cf81d5272a1e288b3f46d70bff8d8ddc2
7
+ data.tar.gz: f47260d1510f30fe4e23c42e93364366be0ffeee930a5972362a370252108ade399c81e5ec2179ab5f31fd1bba093771213f112771d567d8a1c0672b45c4b785
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
@@ -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.2".freeze
11
+ VERSION = "2.3.1".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
 
@@ -32,20 +42,24 @@ module RbFind
32
42
  @rows.empty?
33
43
  end
34
44
 
35
- def output head: false
45
+ def output head: false, ifempty: nil
46
+ if empty? and ifempty then
47
+ puts ifempty
48
+ return
49
+ end
36
50
  make_lines head: head do |l| puts l end
37
51
  end
38
52
 
39
53
  def make_lines head: false
40
54
  rs = @rows
41
- rs.unshift heads_plain if head
55
+ rs.unshift @heads.map { |(h,a)| h } if head
42
56
  w = calc_widths
43
57
  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
58
+ j = (w.zip @heads, r).map { |v,(_,a),c|
59
+ case a
60
+ when -1 then c.ljust v
61
+ when 0 then c.center v
62
+ when +1 then c.rjust v
49
63
  end
50
64
  }
51
65
  l = j.join " "
@@ -59,14 +73,14 @@ module RbFind
59
73
  @html = ""
60
74
  tag :table, table, nl: 2 do
61
75
  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
76
+ @heads.each { |(h,a)|
77
+ tag :td, h.downcase, align: a do @html << h end
64
78
  }
65
79
  end
66
80
  @rows.each { |r|
67
81
  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
82
+ (@heads.zip r).each { |(g,a),c|
83
+ tag :td, g.downcase, align: a do @html << c end
70
84
  }
71
85
  end
72
86
  }
@@ -86,13 +100,9 @@ module RbFind
86
100
  w
87
101
  end
88
102
 
89
- def heads_plain
90
- @heads.map { |h| h.sub /\W\z/, "" }
91
- end
92
-
93
103
  def tag name, cls, nl: 0, align: nil
94
104
  @html << "<#{name}"
95
- @html << " style=\"text-align: " << align << ";\"" if align
105
+ @html << " style=\"text-align: " << (html_align align) << ";\"" if align
96
106
  @html << " class=\"" << cls << "\"" if cls
97
107
  @html << ">"
98
108
  @html << $/ if nl > 1
@@ -101,11 +111,11 @@ module RbFind
101
111
  @html << $/ if nl > 0
102
112
  end
103
113
 
104
- def html_align h
105
- case h
106
- when />/ then "right"
107
- when /\^/ then "center"
108
- when /<?/ then "left"
114
+ def html_align a
115
+ case a
116
+ when -1 then "left"
117
+ when 0 then "center"
118
+ when +1 then "right"
109
119
  end
110
120
  end
111
121
 
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.2
4
+ version: 2.3.1
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-07-14 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