rbfind 2.13 → 2.14.1
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/LICENSE +31 -13
- data/README.md +61 -0
- data/bin/rbfind +99 -171
- data/lib/rbfind/appl.rb +158 -0
- data/lib/rbfind/core.rb +0 -1
- data/lib/rbfind/csv.rb +1 -0
- data/lib/rbfind/table.rb +1 -0
- data/lib/rbfind.rb +5 -4
- metadata +8 -10
- data/README +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d750bcaf97eb7cb1c8bdf3d5da1fd091504914e513b0ca1f078e319786a8741
|
4
|
+
data.tar.gz: 600367ca7afd454f9f7389b5e070e1049092b54111701e608277a80ace4f0cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a888f1f8c8d4637e2bb010d2b1d43bdae5f6ff2a466bff266736a23051fea02168369dc182f8b7c27067727181f5a6c45ac6d4c09550d571846dd3a3f74e6b00
|
7
|
+
data.tar.gz: 1542a6f350f2c5687ef2fb4f2a07dac150c9811c62adea5abbb95afa649a095d4007c5260e0e87f83031970febcf7e46ce874427295ebd4b3f2a50da6e7c4623
|
data/LICENSE
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
|
2
|
-
| _ \| |__ | ___(_)_ __ __| |
|
3
|
-
| |_) | '_ \| |_ | | '_ \ / _` |
|
4
|
-
| _ <| |_) | _| | | | | | (_| |
|
5
|
-
|_| \_\_.__/|_| |_|_| |_|\__,_|
|
1
|
+
# BSD-2-clause license, extended by language use conditions
|
6
2
|
|
7
|
-
|
8
|
-
Copyright (c) 2008-2019, Bertram Scharpf <software@bertram-scharpf.de>.
|
3
|
+
Copyright (C) 2008-2025, Bertram Scharpf <software@bertram-scharpf.de>.
|
9
4
|
All rights reserved.
|
10
5
|
|
11
6
|
Redistribution and use in source and binary forms, with or without
|
12
7
|
modification, are permitted provided that the following conditions are
|
13
8
|
met:
|
14
9
|
|
15
|
-
|
16
|
-
|
10
|
+
* Redistributions of source code must retain the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer.
|
12
|
+
|
13
|
+
* Redistributions in binary form must reproduce the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer in
|
15
|
+
the documentation and/or other materials provided with the
|
16
|
+
distribution.
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
* Redistributions must not contain any clauses about anticipated
|
19
|
+
harassment or discrimination, nor must they be held in a so-called
|
20
|
+
"inclusive language". As far as German language is used, the
|
21
|
+
conditions mentioned below additionally apply.
|
22
22
|
|
23
23
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
24
24
|
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
@@ -32,3 +32,21 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
32
32
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
33
33
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
34
|
|
35
|
+
|
36
|
+
## Use of the German Language
|
37
|
+
|
38
|
+
Beim Gebrauch deutscher Sprache sind Weiterentwicklungen und
|
39
|
+
-verbreitungen nur gestattet unter Einhaltung sowie abermaligen
|
40
|
+
Einforderns folgender zusätzlicher Bedingungen:
|
41
|
+
|
42
|
+
* Keine Verwendung von sogenannter „geschlechtergerechter Sprache“,
|
43
|
+
also Anfügen von weiblichen Endungen mit Binnen-I, Sternchen,
|
44
|
+
Doppelpunkt, Unterstrich oder ähnlichem, oder Konstruktionen, die
|
45
|
+
den Sachverhalt falsch wiedergeben („Radfahrende“, „Studierende“).
|
46
|
+
|
47
|
+
* Keine Verwendung der „reformierten Rechtschreibung“ von 1996,
|
48
|
+
insbesondere Doppel-S am Silbenende, „plazieren“ mit T, sowie
|
49
|
+
Großschreibung von Wendungen wie „des weiteren“.
|
50
|
+
|
51
|
+
|
52
|
+
<!-- vim:set ft=markdown : -->
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# RbFind
|
2
|
+
|
3
|
+
A substitute for the Unix find tool using Ruby expressions
|
4
|
+
|
5
|
+
|
6
|
+
## Description
|
7
|
+
|
8
|
+
RbFind does the same as the standard Unix find tool but has a
|
9
|
+
different calling syntax. Specify your search reqest as a
|
10
|
+
Ruby expression.
|
11
|
+
|
12
|
+
|
13
|
+
## Features
|
14
|
+
|
15
|
+
* ls long format style output
|
16
|
+
* Built-in grep
|
17
|
+
* Colored ls and grep output
|
18
|
+
* Automatically exclude version control system or Vim swap files
|
19
|
+
* No dependecies
|
20
|
+
|
21
|
+
|
22
|
+
## Example
|
23
|
+
|
24
|
+
Find files that were modified in the last five minutes.
|
25
|
+
|
26
|
+
```sh
|
27
|
+
rbfind -p 'file and age < 5.m'
|
28
|
+
```
|
29
|
+
|
30
|
+
Grep whole directory but skip `.git/` or `.svn/`, and
|
31
|
+
`.filename.swp`.
|
32
|
+
|
33
|
+
```sh
|
34
|
+
rbfind -CWg require
|
35
|
+
```
|
36
|
+
|
37
|
+
Save time and do not grep large files.
|
38
|
+
|
39
|
+
```sh
|
40
|
+
rbfind 'filesize < 100.kB and grep /require/'
|
41
|
+
```
|
42
|
+
|
43
|
+
Output ls long format.
|
44
|
+
|
45
|
+
```sh
|
46
|
+
rbfind -P
|
47
|
+
```
|
48
|
+
|
49
|
+
Print MD5 digest and size for each file.
|
50
|
+
|
51
|
+
```sh
|
52
|
+
rbfind 'spacesep digest_md5, size.w8, path'
|
53
|
+
```
|
54
|
+
|
55
|
+
|
56
|
+
## Copyright
|
57
|
+
|
58
|
+
* (C) 2008-2025, Bertram Scharpf <software@bertram-scharpf.de>
|
59
|
+
* License: [BSD-2-Clause+](./LICENSE)
|
60
|
+
* Repository: [ruby-nvim](https://github.com/BertramScharpf/rbfind.git)
|
61
|
+
|
data/bin/rbfind
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#
|
4
4
|
# rbfind -- Ruby Find with many features
|
@@ -6,13 +6,12 @@
|
|
6
6
|
|
7
7
|
require "rbfind"
|
8
8
|
require "rbfind/humansiz"
|
9
|
-
require
|
10
|
-
require 'getoptlong'
|
9
|
+
require 'rbfind/appl'
|
11
10
|
|
12
11
|
|
13
12
|
module RbFind
|
14
13
|
|
15
|
-
class Application
|
14
|
+
class RbFindAppl < Application
|
16
15
|
|
17
16
|
PROGRAM = <<~EOT
|
18
17
|
rbfind #{RbFind::VERSION} -- A find tool using Ruby
|
@@ -21,129 +20,65 @@ module RbFind
|
|
21
20
|
License: BSD
|
22
21
|
EOT
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
def initialize
|
23
|
+
option %w(h help ), "print this help" do usage ; raise Exit ; end
|
24
|
+
option %w(X examples ), "print this help and examples" do usage_examples ; raise Exit ; end
|
25
|
+
option %w(V version ), "print version information" do puts PROGRAM ; raise Exit ; end
|
26
|
+
option %w(v verbose ), "standard Ruby error reports" do @verbose = true ; end
|
27
|
+
option %w(o show ), "just show Ruby block built from options" do @show = true ; end
|
28
|
+
option %w(w bw ), "black and white on -p or default output" do @color = false ; end
|
29
|
+
option %w(c colored ), "force color on -p or default output" do @color = true ; end
|
30
|
+
option %w(d depth ), "yield directory after its contents" do @params[ :depth_first] = true ; end
|
31
|
+
option %w(m maxdepth ), "maxium step depth (0 = any)" do |num| @params[ :max_depth] = num.to_i.nonzero? ; end
|
32
|
+
option %w(A argsdepth ), "args have depth 1 (not 0)" do @params[ :args_depth] = true ; end
|
33
|
+
option %w(y follow ), "follow symbolic links" do @params[ :follow] = true ; end
|
34
|
+
option %w(U nosort ), "unsorted" do @params[ :sort] = false ; end
|
35
|
+
option %w(s sort-by ), "sort expression" do |str| @params[ :sort] = instance_eval "proc { #{str} }" ; end
|
36
|
+
option %w(R reverse ), "reverse the sort" do @params[ :reverse] = !@params[ :reverse] ; end
|
37
|
+
option %w(t time ), "sort by time, newest first" do @params[ :sort] = proc { mtime } ; @params[ :reverse] = true ; end
|
38
|
+
option %w(S size ), "sort by size, largest first" do @params[ :sort] = proc { size } ; @params[ :reverse] = true ; end
|
39
|
+
option %w(F dirs ), "sort directories before files" do @params[ :dirs] = true ; end
|
40
|
+
option %w(r require ), "require library" do |rb| require rb ; end
|
41
|
+
option %w(x execute ), "execute block" do |b| @block = b ; end
|
42
|
+
option %w(p puts-path ), "do 'puts path/cpath' on true block" do @puts = :plain ; end
|
43
|
+
option %w(P ls-l ), "do 'ls -l' style output on true block" do @puts = :ls ; @wds ||= 6 ; @wdu ||= 6 ; end
|
44
|
+
option %w(Q long ), "alternate long format on true block" do @puts = :alt ; @wds ||= 7 ; @wdu ||= 4 ; end
|
45
|
+
option %w(H humanage ), "long format with human readable ages" do @puts = :hum ; @wds ||= 7 ; @wdu ||= 4 ; end
|
46
|
+
option %w(J ino ), "show inodes and number of hard links" do @puts = :ino ; @wds ||= 8 ; @wdu ||= 2 ; end
|
47
|
+
option %w(+ wider ), "widen fields in long output format" do @wdu and @wdu += 2 ; @wds and @wds += @puts != :ls ? 4 : 3 ; end
|
48
|
+
option %w(/ slash ), "append a slash to directory names" do @slash = true ; end
|
49
|
+
option %w(l lines ), "surround block by 'lines { |$_,$.| ... }'" do |blk| @lines = :plain ; @block = blk ; end
|
50
|
+
option %w(L reallines ), "same as -l but stop at any null character" do |blk| @lines = :plain ; @real = true ; @block = blk ; end
|
51
|
+
option %w(g grep ), "grep files (implies -pL)" do |blk| @lines = :grep ; @block = blk ; end
|
52
|
+
option %w(G igrep ), "case insensitive grep" do |blk| @lines = :grep ; @icase = true ; @block = blk ; end
|
53
|
+
option %w(b binary ), "grep even binary files" do @binary = true ; end
|
54
|
+
option %w(C no-vcs ), "prune version control dirs (CVS/.svn/.git)" do @vcs = true ; end
|
55
|
+
option %w(W no-swap ), "ignore Vim swapfiles" do @vim = true ; end
|
56
|
+
option %w(k skip ), "filenames to skip" do |rgx| @skip = rgx ; end
|
57
|
+
option %w(D demand ), "skip all filenames but these" do |rgx| @demand = rgx ; end
|
58
|
+
option %w(e ext ), "skip all filename extensions but these" do |lst| @ext = lst ; end
|
59
|
+
option %w(I visible ), "skip all hidden (starting with .dot)" do @visible = true ; end
|
60
|
+
option %w(a all ), "all, including hidden (starting with .dot)" do @visible = false ; end
|
61
|
+
option %w(i icase ), "ignore case in file and path matches" do @icase = true ; end
|
62
|
+
option %w(N nodirs ), "skip directories" do @nodirs = true ; end
|
63
|
+
option %w(B begin ), "eval block before begin" do |blk| @blkbegin = blk ; end
|
64
|
+
option %w(E end ), "eval block after end" do |blk| @blkend = blk ; end
|
65
|
+
option %w(f file ), "read block expression from file" do |nam| @block = File.read nam ; end
|
66
|
+
option %w(K encoding ), "encoding extern[:intern] (same as ruby -E)" do |str| e, i = str.split ":", 2 ; set_encoding e, i ; end
|
67
|
+
option %w( width-user), "width of user field" do |num| @wdu = num.to_i.nonzero? ; end
|
68
|
+
option %w( width-size), "width of size field" do |num| @wds = num.to_i.nonzero? ; end
|
69
|
+
|
70
|
+
def initialize args
|
74
71
|
@params = {}
|
75
72
|
envopts = ENV[ "RBFIND_OPTIONS"]
|
76
|
-
|
77
|
-
|
78
|
-
[*
|
79
|
-
|
80
|
-
opts.ordering = GetoptLong::PERMUTE
|
81
|
-
opts.quiet = true
|
82
|
-
opts.each do |opt,arg|
|
83
|
-
case opt
|
84
|
-
when '--help' then usage ; exit
|
85
|
-
when '--version' then puts PROGRAM ; exit
|
86
|
-
when '--examples' then usage_examples ; exit
|
87
|
-
when '--verbose' then @verbose = true
|
88
|
-
when '--show' then @show = true
|
89
|
-
when '--bw' then @color = false
|
90
|
-
when '--colored' then @color = true
|
91
|
-
when '--depth' then @params[ :depth_first] = true
|
92
|
-
when '--maxdepth' then @params[ :max_depth] = arg.to_i.nonzero?
|
93
|
-
when '--argsdepth' then @params[ :args_depth] = true
|
94
|
-
when '--follow' then @params[ :follow] = true
|
95
|
-
when '--nosort' then @params[ :sort] = false
|
96
|
-
when '--sort-by' then @params[ :sort] = instance_eval "proc { #{arg} }"
|
97
|
-
when '--time' then @params[ :sort] = proc { mtime } ; @params[ :reverse] = true
|
98
|
-
when '--size' then @params[ :sort] = proc { size } ; @params[ :reverse] = true
|
99
|
-
when '--dirs' then @params[ :dirs] = true
|
100
|
-
when '--reverse' then @params[ :reverse] = !@params[ :reverse]
|
101
|
-
when '--require' then require arg
|
102
|
-
when '--puts-path' then @puts = true
|
103
|
-
when '--ls-l' then @puts = :ls ; @wds ||= 6 ; @wdu ||= 6
|
104
|
-
when '--long' then @puts = :alt ; @wds ||= 7 ; @wdu ||= 4
|
105
|
-
when '--humanage' then @puts = :hum ; @wds ||= 7 ; @wdu ||= 4
|
106
|
-
when '--ino' then @puts = :ino ; @wds ||= 8 ; @wdu ||= 2
|
107
|
-
when '--wider' then @wdu and @wdu += 2 ; @wds and @wds += @puts != :ls ? 4 : 3
|
108
|
-
when '--slash' then @slash = true
|
109
|
-
when '--lines' then @lines = :plain ; @block = arg
|
110
|
-
when '--reallines' then @lines = :plain ; @real = true ; @block = arg
|
111
|
-
when '--grep' then @lines = :grep ; @block = arg
|
112
|
-
when '--igrep' then @lines = :grep ; @icase = true ; @block = arg
|
113
|
-
when '--binary' then @binary = true
|
114
|
-
when '--no-vcs' then @vcs = true
|
115
|
-
when '--no-swap' then @vim = true
|
116
|
-
when '--skip' then @skip = arg
|
117
|
-
when '--demand' then @demand = arg
|
118
|
-
when '--ext' then @ext = arg
|
119
|
-
when '--visible' then @visible = true
|
120
|
-
when '--all' then @visible = false
|
121
|
-
when '--icase' then @icase = true
|
122
|
-
when '--nodirs' then @nodirs = true
|
123
|
-
when '--begin' then @blkbegin = arg
|
124
|
-
when '--end' then @blkend = arg
|
125
|
-
when '--file' then @block = File.open arg do |f| f.each { |l| l.chomp! } end
|
126
|
-
when '--encoding' then e, i = arg.split ":" ; set_encoding e, i
|
127
|
-
when '--width-user' then @wdu = arg.to_i.nonzero?
|
128
|
-
when '--width-size' then @wds = arg.to_i.nonzero?
|
73
|
+
if envopts then
|
74
|
+
e = []
|
75
|
+
envopts.scan /"((?:[^"\\]|\\.)*)"|'([^']*)'|(\S+)/ do
|
76
|
+
e.push $1 ? (eval $1) : ($2 || $3)
|
129
77
|
end
|
78
|
+
args.unshift *e
|
130
79
|
end
|
131
|
-
|
132
|
-
if @args.empty? and not $stdin.tty? then
|
133
|
-
$stdin.each_line { |l|
|
134
|
-
l.chomp!
|
135
|
-
@args.push l
|
136
|
-
}
|
137
|
-
end
|
80
|
+
super args
|
138
81
|
build_block
|
139
|
-
rescue GetoptLong::InvalidOption
|
140
|
-
$stderr.puts $!
|
141
|
-
$stderr.puts
|
142
|
-
usage
|
143
|
-
exit 9
|
144
|
-
rescue
|
145
|
-
$stderr.puts $!
|
146
|
-
exit 8
|
147
82
|
end
|
148
83
|
|
149
84
|
def run
|
@@ -182,28 +117,27 @@ module RbFind
|
|
182
117
|
(Regexp.new str, flags).inspect
|
183
118
|
end
|
184
119
|
|
185
|
-
def
|
120
|
+
def treat_last_arg_as_file
|
186
121
|
l = @args.last
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
return if l =~ %r(\A\S*/\w*[^imoxuesn]\w*\b(?!:/))
|
192
|
-
end
|
193
|
-
true
|
122
|
+
not l or
|
123
|
+
File.exist? l or
|
124
|
+
l.start_with? "." or
|
125
|
+
(not l =~ /[;<>{}\[\]()*?'"!&|~ ]/ and l =~ %r(/))
|
194
126
|
end
|
195
127
|
|
196
128
|
def join_code a, ind = 0
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
129
|
+
r = a.map { |e|
|
130
|
+
q = case e
|
131
|
+
when Array then
|
132
|
+
join_code e, ind + 1
|
133
|
+
else
|
134
|
+
INDENT * ind + e.to_s
|
135
|
+
end
|
136
|
+
q.rstrip!
|
137
|
+
q unless q.empty?
|
138
|
+
}
|
139
|
+
r.compact!
|
140
|
+
r.join "\n"
|
207
141
|
end
|
208
142
|
|
209
143
|
def build_block
|
@@ -214,47 +148,46 @@ module RbFind
|
|
214
148
|
when :plain then
|
215
149
|
@block = [ @block]
|
216
150
|
@puts and @block = [ "if (", @block, ") then", [ "colsep #{opath}, num, line"], "end" ]
|
217
|
-
@real and
|
151
|
+
@real and @block.unshift "break if ~/\\0/o"
|
218
152
|
@block = [ "lines { |line,num|", [ "$_, $. = line, num"], @block, "}"]
|
219
153
|
|
220
154
|
when :grep then
|
221
155
|
ic = Regexp::IGNORECASE if @icase
|
222
156
|
color = ", true" if co
|
223
|
-
@block = [ "grep %r#{build_re @block, ic}#{color}"]
|
157
|
+
@block = [ "grep %r#{build_re @block.to_s, ic}#{color}"]
|
224
158
|
@block.push "$stdout.flush" unless $stdout.tty?
|
225
159
|
@binary or @block = [ "unless binary? then", @block, "end"]
|
226
160
|
|
227
161
|
else
|
228
162
|
unless @block then
|
229
|
-
if
|
230
|
-
@block =
|
163
|
+
if treat_last_arg_as_file then
|
164
|
+
@block = "true"
|
165
|
+
@puts ||= :plain
|
231
166
|
else
|
232
|
-
@
|
167
|
+
@block = @args.pop
|
233
168
|
end
|
234
169
|
end
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
@block = [ "if (", [ cond], ") then", @block, "end"] if cond
|
245
|
-
end
|
170
|
+
@block = [ @block]
|
171
|
+
output = case @puts
|
172
|
+
when :ls then long_fmt false, false, "mtime.lsish", opath, co
|
173
|
+
when :alt then long_fmt true, true, "mtime.long", opath, co
|
174
|
+
when :hum then long_fmt true, true, "mage.t.r4", opath, co
|
175
|
+
when :ino then [ "spcsep ino.w8, nlink.w2, #{opath}"]
|
176
|
+
when :plain then [ "puts #{opath}"]
|
177
|
+
end
|
178
|
+
output and @block = [ "if (", @block, ") then", output, "end"]
|
246
179
|
|
247
180
|
end
|
248
181
|
|
249
182
|
osic = Regexp::IGNORECASE if File::ALT_SEPARATOR || @icase
|
250
|
-
@skip and
|
251
|
-
@demand and
|
252
|
-
@ext and
|
183
|
+
@skip and @block.unshift "done if name =~ #{build_re @skip, osic}"
|
184
|
+
@demand and @block.unshift "done unless name =~ #{build_re @demand, osic}"
|
185
|
+
@ext and @block.unshift "done unless ext =~ #{build_re_ext osic}"
|
253
186
|
|
254
|
-
@visible and
|
255
|
-
@nodirs and
|
256
|
-
@vcs and
|
257
|
-
@vim and
|
187
|
+
@visible and @block.unshift "done unless visible?"
|
188
|
+
@nodirs and @block.unshift "done if dir?"
|
189
|
+
@vcs and @block.unshift "no_vcs"
|
190
|
+
@vim and @block.unshift "done if vimswap?"
|
258
191
|
|
259
192
|
@params[ :error] = proc do
|
260
193
|
case $!
|
@@ -275,13 +208,9 @@ module RbFind
|
|
275
208
|
rbfind [options] path... 'block'
|
276
209
|
|
277
210
|
EOT
|
278
|
-
|
279
|
-
puts " %-12s %2s %-5s %s" % [long,short,arg.to_s.upcase,desc]
|
280
|
-
}
|
211
|
+
self.class.usage
|
281
212
|
puts <<~'EOT'
|
282
213
|
|
283
|
-
"--" stops option processing.
|
284
|
-
|
285
214
|
The last argument is a block that will be executed on every found
|
286
215
|
file object. It may be omitted; then "puts path" is assumed, or
|
287
216
|
"puts cpath" in case the output is a terminal.
|
@@ -489,9 +418,8 @@ class Time
|
|
489
418
|
|
490
419
|
# autoload several formating methods
|
491
420
|
def method_missing sym, *args, &block
|
421
|
+
require "time" and return send sym, *args, &block
|
492
422
|
super
|
493
|
-
rescue NoMethodError, NameError
|
494
|
-
send sym, *args, &block if require "time"
|
495
423
|
end
|
496
424
|
|
497
425
|
# several common schemes
|
@@ -566,5 +494,5 @@ class Proc
|
|
566
494
|
end
|
567
495
|
|
568
496
|
|
569
|
-
RbFind::
|
497
|
+
RbFind::RbFindAppl.run
|
570
498
|
|
data/lib/rbfind/appl.rb
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
#
|
2
|
+
# rbfind/appl.rb -- Option parsing etc.
|
3
|
+
#
|
4
|
+
|
5
|
+
|
6
|
+
module RbFind
|
7
|
+
|
8
|
+
class Application
|
9
|
+
|
10
|
+
class Exit < Exception ; end
|
11
|
+
|
12
|
+
class OptError < StandardError
|
13
|
+
def initialize opt
|
14
|
+
super "Unknown option: #{opt}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
class <<self
|
20
|
+
|
21
|
+
def inherited cls
|
22
|
+
cls.init_opts
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :options
|
26
|
+
attr_accessor :debug
|
27
|
+
|
28
|
+
def init_opts
|
29
|
+
@options, @optdocs = {}, []
|
30
|
+
end
|
31
|
+
|
32
|
+
def option names, doc, &block
|
33
|
+
names.each { |n| @options[ n] = block }
|
34
|
+
@optdocs.push [ names, doc]
|
35
|
+
end
|
36
|
+
|
37
|
+
def run
|
38
|
+
exit (new $*).run.to_i
|
39
|
+
rescue Exit
|
40
|
+
exit 0
|
41
|
+
rescue OptError
|
42
|
+
$stderr.puts $!
|
43
|
+
usage
|
44
|
+
exit 15
|
45
|
+
rescue
|
46
|
+
raise if @debug
|
47
|
+
$stderr.puts $!
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
|
51
|
+
def usage
|
52
|
+
omax, amax, l = 0, 0, []
|
53
|
+
@optdocs.each { |names,desc|
|
54
|
+
m = names.map { |n| (n.length > 1 ? "--" : "-") + n }.join " "
|
55
|
+
omax = m.length if m.length > omax
|
56
|
+
_, arg = @options[ names.first].parameters.first
|
57
|
+
if arg then
|
58
|
+
a = arg.upcase
|
59
|
+
amax = a.length if a.length > amax
|
60
|
+
end
|
61
|
+
l.push [ m, a, desc]
|
62
|
+
}
|
63
|
+
l.push [ "--", nil, "stop option processing"]
|
64
|
+
fmt = " %%-%ds %%-%ds %%s" % [ omax, amax]
|
65
|
+
l.each { |mad| puts fmt % mad }
|
66
|
+
end
|
67
|
+
|
68
|
+
def process_options args
|
69
|
+
rest = []
|
70
|
+
loop do
|
71
|
+
arg, *args = *args
|
72
|
+
arg or break
|
73
|
+
if arg =~ /^-/ then
|
74
|
+
arg = $'
|
75
|
+
if arg =~ /^-/ then
|
76
|
+
arg = $'
|
77
|
+
if arg.empty? then
|
78
|
+
rest.concat args
|
79
|
+
break
|
80
|
+
end
|
81
|
+
arg, val = arg.split "=", 2
|
82
|
+
opt = @options[ arg] or raise OptError, "--#{arg}"
|
83
|
+
if val then
|
84
|
+
opt.parameters.empty? and raise OptError, "--#{args}=value"
|
85
|
+
yield opt, val
|
86
|
+
else
|
87
|
+
unless opt.parameters.empty? then
|
88
|
+
if opt.arity.nonzero? or args.first !~ /^-/ then
|
89
|
+
arg, *args = *args
|
90
|
+
else
|
91
|
+
arg = nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
yield opt, arg
|
95
|
+
end
|
96
|
+
else
|
97
|
+
loop do
|
98
|
+
a = arg.slice! 0, 1
|
99
|
+
a.empty? and break
|
100
|
+
opt = @options[ a] or raise OptError, "-#{a}"
|
101
|
+
if opt.parameters.empty? then
|
102
|
+
yield opt
|
103
|
+
else
|
104
|
+
if arg.empty? then
|
105
|
+
if opt.arity.nonzero? or args.first !~ /^-/ then
|
106
|
+
arg, *args = *args
|
107
|
+
end
|
108
|
+
end
|
109
|
+
yield opt, arg
|
110
|
+
break
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
else
|
115
|
+
rest.push arg
|
116
|
+
end
|
117
|
+
end
|
118
|
+
rest
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
def initialize args
|
124
|
+
@args = self.class.process_options args do |opt,arg|
|
125
|
+
if arg then
|
126
|
+
instance_exec arg, &opt
|
127
|
+
else
|
128
|
+
instance_exec &opt
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
if __FILE__ == $0 then
|
137
|
+
|
138
|
+
class DummyAppl < Application
|
139
|
+
|
140
|
+
option %w(q qqq), "Do Qs" do @q = @q.to_i.pred end
|
141
|
+
option %w(x xxx), "Do Xs" do @x = @x.to_i.succ end
|
142
|
+
option %w(y yyy), "Do Ys" do |arg| @y = arg end
|
143
|
+
option %w(z zzz), "Do Zs" do |arg=3| @z = arg end
|
144
|
+
option %w(h help), "This help" do self.class.usage ; raise Exit ; end
|
145
|
+
option %w(g debug), "Debug info" do self.class.debug = true end
|
146
|
+
|
147
|
+
def run
|
148
|
+
puts inspect
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
DummyAppl.run
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
data/lib/rbfind/core.rb
CHANGED
data/lib/rbfind/csv.rb
CHANGED
data/lib/rbfind/table.rb
CHANGED
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.14.1".freeze
|
12
12
|
|
13
13
|
=begin rdoc
|
14
14
|
|
@@ -367,9 +367,10 @@ Sort without case sensitivity and preceding dot:
|
|
367
367
|
@params.sort.call list
|
368
368
|
list.reverse! if @params.reverse
|
369
369
|
if @params.dirs then
|
370
|
-
|
371
|
-
|
372
|
-
list.
|
370
|
+
df = list.partition { |e| e.rstat.directory? rescue nil }
|
371
|
+
df.reverse! if @params.depth_first
|
372
|
+
list.clear
|
373
|
+
list.concat *df
|
373
374
|
end
|
374
375
|
end
|
375
376
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbfind
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.14.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bertram Scharpf
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: |
|
13
13
|
A replacement for the standard UNIX command find.
|
@@ -20,24 +20,22 @@ executables:
|
|
20
20
|
extensions: []
|
21
21
|
extra_rdoc_files:
|
22
22
|
- LICENSE
|
23
|
+
- README.md
|
23
24
|
files:
|
24
25
|
- LICENSE
|
25
|
-
- README
|
26
|
+
- README.md
|
26
27
|
- bin/rbfind
|
27
28
|
- lib/rbfind.rb
|
29
|
+
- lib/rbfind/appl.rb
|
28
30
|
- lib/rbfind/core.rb
|
29
31
|
- lib/rbfind/csv.rb
|
30
32
|
- lib/rbfind/humansiz.rb
|
31
33
|
- lib/rbfind/table.rb
|
32
34
|
homepage: http://www.bertram-scharpf.de/software/rbfind
|
33
35
|
licenses:
|
34
|
-
- BSD-2-Clause
|
36
|
+
- BSD-2-Clause+
|
35
37
|
metadata: {}
|
36
|
-
rdoc_options:
|
37
|
-
- "--charset"
|
38
|
-
- utf-8
|
39
|
-
- "--main"
|
40
|
-
- README
|
38
|
+
rdoc_options: []
|
41
39
|
require_paths:
|
42
40
|
- lib
|
43
41
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -52,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
50
|
version: '0'
|
53
51
|
requirements:
|
54
52
|
- Just Ruby
|
55
|
-
rubygems_version: 3.
|
53
|
+
rubygems_version: 3.7.1
|
56
54
|
specification_version: 4
|
57
55
|
summary: Ruby replacement for the standard Unix find tool
|
58
56
|
test_files: []
|
data/README
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
= RbFind
|
2
|
-
|
3
|
-
A substitute for the Unix find tool using Ruby expressions
|
4
|
-
|
5
|
-
== Description
|
6
|
-
|
7
|
-
RbFind does the same as the standard Unix find tool but has a
|
8
|
-
different calling syntax. You may specify your search reqest as a
|
9
|
-
Ruby expression.
|
10
|
-
|
11
|
-
== Features
|
12
|
-
|
13
|
-
* ls long format style output
|
14
|
-
* Built-in grep
|
15
|
-
* Colored ls and grep output
|
16
|
-
* Automatically exclude version control system or Vim swap files
|
17
|
-
* No dependecies
|
18
|
-
|
19
|
-
== Example
|
20
|
-
|
21
|
-
Find files that were modified in the last five minutes.
|
22
|
-
|
23
|
-
$ rbfind -p 'file and age < 5.m'
|
24
|
-
|
25
|
-
Grep whole directory but skip ".git/" or ".svn/", and
|
26
|
-
".filename.swp".
|
27
|
-
|
28
|
-
$ rbfind -CWg require
|
29
|
-
|
30
|
-
Save time and do not grep large files.
|
31
|
-
|
32
|
-
$ rbfind 'filesize < 100.kB and grep /require/'
|
33
|
-
|
34
|
-
Output ls long format.
|
35
|
-
|
36
|
-
$ rbfind -P
|
37
|
-
|
38
|
-
Print MD5 digest and size for each file.
|
39
|
-
|
40
|
-
$ rbfind 'spacesep digest_md5, size.w8, path'
|
41
|
-
|
42
|
-
== Copyright
|
43
|
-
|
44
|
-
(C) 2008-2014, Bertram Scharpf <software@bertram-scharpf.de>
|
45
|
-
|