prak 1.3 → 1.3.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.
- data/Manifest.txt +1 -0
- data/Rakefile +3 -2
- data/lib/prak/command_line.rb +8 -8
- data/lib/prak/compile_match_file.rb +2 -1
- data/lib/prak/file.rb +7 -1
- data/lib/prak/help.rb +88 -0
- data/lib/prak/search.rb +5 -4
- data/lib/prak.rb +1 -1
- metadata +7 -6
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
|
@@ -7,8 +7,9 @@ $:.unshift 'lib'
|
|
|
7
7
|
require 'prak'
|
|
8
8
|
|
|
9
9
|
Hoe.spec('prak') do |p|
|
|
10
|
-
p.author = 'Sven Winkler'
|
|
11
|
-
p.email = '
|
|
10
|
+
p.author = 'Sven Winkler (originally Daniel Lucraft)'
|
|
11
|
+
p.email = 'svenwn@gmail.com'
|
|
12
|
+
p.url = %q{http://github.com/sven-q/prak}
|
|
12
13
|
p.version = Prak::VERSION
|
|
13
14
|
p.summary = 'A grep replacement in Ruby, type "$prak pattern".'
|
|
14
15
|
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
data/lib/prak/command_line.rb
CHANGED
|
@@ -66,14 +66,12 @@ class Prak
|
|
|
66
66
|
|
|
67
67
|
FILE_TYPES.each do |type, exts|
|
|
68
68
|
if ARGV.delete('--'+type.to_s)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
end
|
|
69
|
+
ARGV << '--type'
|
|
70
|
+
ARGV << type.to_s
|
|
72
71
|
end
|
|
73
72
|
if ARGV.delete('--no'+type.to_s)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
end
|
|
73
|
+
ARGV << '--type'
|
|
74
|
+
ARGV << 'no'+type.to_s
|
|
77
75
|
end
|
|
78
76
|
end
|
|
79
77
|
|
|
@@ -114,7 +112,7 @@ class Prak
|
|
|
114
112
|
[ '-x', '--line-regexp', GetoptLong::NO_ARGUMENT ],
|
|
115
113
|
[ '-s', '--line-start', GetoptLong::NO_ARGUMENT ],
|
|
116
114
|
[ '-e', '--line-end', GetoptLong::NO_ARGUMENT ],
|
|
117
|
-
[ '-E', '--encoding', GetoptLong::REQUIRED_ARGUMENT ]
|
|
115
|
+
[ '-E', '--encoding', GetoptLong::REQUIRED_ARGUMENT ]
|
|
118
116
|
)
|
|
119
117
|
|
|
120
118
|
self.standard_options
|
|
@@ -133,10 +131,12 @@ class Prak
|
|
|
133
131
|
case option
|
|
134
132
|
when '--help'
|
|
135
133
|
if arg == ""
|
|
136
|
-
# TODO: USAGE_HELP
|
|
137
134
|
puts USAGE_HELP
|
|
138
135
|
elsif arg == "types" or arg == "type"
|
|
139
136
|
puts TYPES_HELP
|
|
137
|
+
FILE_TYPES.sort_by{|type,exts| type.to_s}.each do |type, exts|
|
|
138
|
+
puts " --[no]%-13s %s\n" % [type, exts.join(" ")]
|
|
139
|
+
end
|
|
140
140
|
end
|
|
141
141
|
exit
|
|
142
142
|
when '--max-count'
|
|
@@ -115,7 +115,8 @@ class Prak
|
|
|
115
115
|
c << %{ prefix = "\#{i.to_s.rjust(4) }|" }
|
|
116
116
|
else
|
|
117
117
|
if opt[:print_file_each_line]
|
|
118
|
-
c << %{ fn_str = (fn.is_a?(String) ? FILE_COLOUR + fn +
|
|
118
|
+
c << %{ fn_str = (fn.is_a?(String) ? FILE_COLOUR + fn +
|
|
119
|
+
CLEAR_COLOURS + ":" : "") }
|
|
119
120
|
c << %{ prefix = fn_str + "\#{i.to_s }:" }
|
|
120
121
|
else
|
|
121
122
|
c << %{ prefix = "" }
|
data/lib/prak/file.rb
CHANGED
|
@@ -94,7 +94,13 @@ class Prak
|
|
|
94
94
|
|
|
95
95
|
def self.shebang_matches(fn)
|
|
96
96
|
begin
|
|
97
|
-
|
|
97
|
+
if ruby_1_9?
|
|
98
|
+
line = File.open(fn, :encoding => opt[:standard_encoding])
|
|
99
|
+
else
|
|
100
|
+
line = File.open(fn)
|
|
101
|
+
end
|
|
102
|
+
line = line.readline
|
|
103
|
+
|
|
98
104
|
if line =~ /^#!/
|
|
99
105
|
if line =~ /\b(ruby|perl|php|python|make)[0-9.]*\b/i
|
|
100
106
|
FILE_TYPES[$1.downcase.intern].first
|
data/lib/prak/help.rb
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
class Prak
|
|
2
|
+
|
|
3
|
+
USAGE_HELP=<<END
|
|
4
|
+
Usage: rak [OPTION]... PATTERN [FILES]
|
|
5
|
+
|
|
6
|
+
Search for PATTERN in each source file in the tree from cwd on down.
|
|
7
|
+
If [FILES] is specified, then only those files/directories are checked.
|
|
8
|
+
rak will search STDIN only if no FILES are specified.
|
|
9
|
+
|
|
10
|
+
Example: rak -i select
|
|
11
|
+
|
|
12
|
+
Searching:
|
|
13
|
+
-i, --ignore-case Ignore case distinctions
|
|
14
|
+
-v, --invert-match Invert match: select non-matching lines
|
|
15
|
+
-w, --word-regexp Force PATTERN to match only whole words
|
|
16
|
+
-x, --line-regexp Force PATTERN to match only whole lines
|
|
17
|
+
-Q, --literal Quote all metacharacters; expr is literal
|
|
18
|
+
-s, --line-start Match only at the start of a line
|
|
19
|
+
-e, --line-start Match only at the end of a line
|
|
20
|
+
|
|
21
|
+
Search output:
|
|
22
|
+
-l, --files-with-matches
|
|
23
|
+
Only print filenames containing matches
|
|
24
|
+
-L, --files-without-match
|
|
25
|
+
Only print filenames with no match
|
|
26
|
+
-o Show only the part of a line matching PATTERN
|
|
27
|
+
(turns off text highlighting)
|
|
28
|
+
--passthru Print all lines, whether matching or not
|
|
29
|
+
--output=expr Output the evaluation of expr for each line
|
|
30
|
+
(turns off text highlighting)
|
|
31
|
+
-m, --max-count=NUM Stop searching in a file after NUM matches
|
|
32
|
+
-H, --with-filename Print the filename for each match
|
|
33
|
+
-h, --no-filename Suppress the prefixing filename on output
|
|
34
|
+
-c, --count Show number of lines matching per file
|
|
35
|
+
|
|
36
|
+
--group Group matches by file name.
|
|
37
|
+
(default: on when used interactively)
|
|
38
|
+
--nogroup One result per line, including filename, like grep
|
|
39
|
+
(default: on when the output is redirected)
|
|
40
|
+
|
|
41
|
+
--[no]colour Highlight the matching text (default: on unless
|
|
42
|
+
output is redirected, or on Windows)
|
|
43
|
+
|
|
44
|
+
-A NUM, --after-context=NUM
|
|
45
|
+
Print NUM lines of trailing context after matching
|
|
46
|
+
lines.
|
|
47
|
+
-B NUM, --before-context=NUM
|
|
48
|
+
Print NUM lines of leading context before matching
|
|
49
|
+
lines.
|
|
50
|
+
-C [NUM], --context[=NUM]
|
|
51
|
+
Print NUM lines (default 2) of output context.
|
|
52
|
+
|
|
53
|
+
File finding:
|
|
54
|
+
-f Only print the files found, without searching.
|
|
55
|
+
The PATTERN must not be specified.
|
|
56
|
+
--sort-files Sort the found files lexically.
|
|
57
|
+
|
|
58
|
+
File inclusion/exclusion:
|
|
59
|
+
-n No descending into subdirectories
|
|
60
|
+
-g REGEX Only search in files matching REGEX.
|
|
61
|
+
-k REGEX Only search in files not matching REGEX.
|
|
62
|
+
-a, --all All files, regardless of extension (but still skips
|
|
63
|
+
blib, pkg, CVS, _darcs, .git, .pc, RCS, SCCS and .svn dirs)
|
|
64
|
+
--ruby Include only Ruby files.
|
|
65
|
+
--type=ruby Include only Ruby files.
|
|
66
|
+
--noruby Exclude Ruby files.
|
|
67
|
+
--type=noruby Exclude Ruby files.
|
|
68
|
+
See "rak --help type" for supported filetypes.
|
|
69
|
+
--[no]follow Follow symlinks. Default is off.
|
|
70
|
+
|
|
71
|
+
Miscellaneous:
|
|
72
|
+
--help This help
|
|
73
|
+
--version Display version & copyright
|
|
74
|
+
END
|
|
75
|
+
|
|
76
|
+
TYPES_HELP=<<END
|
|
77
|
+
Usage: rak [OPTION]... PATTERN [FILES]
|
|
78
|
+
|
|
79
|
+
The following is the list of filetypes supported by rak. You can
|
|
80
|
+
specify a file type with the --type=TYPE format, or the --TYPE
|
|
81
|
+
format. For example, both --type=ruby and --ruby work.
|
|
82
|
+
|
|
83
|
+
Note that some extensions may appear in multiple types. For example,
|
|
84
|
+
.pod files are both Perl and Parrot.
|
|
85
|
+
|
|
86
|
+
END
|
|
87
|
+
|
|
88
|
+
end
|
data/lib/prak/search.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
class Prak
|
|
2
2
|
|
|
3
|
-
def self.search
|
|
3
|
+
def self.search run_opts = {}
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# command_line_options and sets some standards
|
|
6
|
+
parse_command_line_options if run_opts.empty?
|
|
6
7
|
|
|
7
8
|
unless opt[:colour]
|
|
8
9
|
FILE_COLOUR.replace ""
|
|
@@ -15,7 +16,6 @@ class Prak
|
|
|
15
16
|
puts fn
|
|
16
17
|
end
|
|
17
18
|
elsif ARGV.empty?
|
|
18
|
-
# TODO USAGE_HELP
|
|
19
19
|
puts USAGE_HELP
|
|
20
20
|
exit
|
|
21
21
|
else
|
|
@@ -23,7 +23,8 @@ class Prak
|
|
|
23
23
|
compiled = false
|
|
24
24
|
file_separator = ""
|
|
25
25
|
each_file(ARGV) do |fn|
|
|
26
|
-
# each_file might turn off printing file name,
|
|
26
|
+
# each_file might turn off printing file name,
|
|
27
|
+
# but only before first yield
|
|
27
28
|
unless compiled
|
|
28
29
|
compile_match_file
|
|
29
30
|
compiled = true
|
data/lib/prak.rb
CHANGED
metadata
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: prak
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.3.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
|
-
- Sven Winkler
|
|
8
|
+
- Sven Winkler (originally Daniel Lucraft)
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2011-08-
|
|
12
|
+
date: 2011-08-24 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: hoe
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &2161105640 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ~>
|
|
@@ -21,7 +21,7 @@ dependencies:
|
|
|
21
21
|
version: '2.12'
|
|
22
22
|
type: :development
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *2161105640
|
|
25
25
|
description: ! 'Modifications by Sven Winkler
|
|
26
26
|
|
|
27
27
|
|
|
@@ -34,7 +34,7 @@ description: ! 'Modifications by Sven Winkler
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
Based on the Perl tool ''ack'' by Andy Lester.'
|
|
37
|
-
email:
|
|
37
|
+
email: svenwn@gmail.com
|
|
38
38
|
executables:
|
|
39
39
|
- prak
|
|
40
40
|
extensions: []
|
|
@@ -52,6 +52,7 @@ files:
|
|
|
52
52
|
- lib/prak/bootstrap.rb
|
|
53
53
|
- lib/prak/command_line.rb
|
|
54
54
|
- lib/prak/compile_match_file.rb
|
|
55
|
+
- lib/prak/help.rb
|
|
55
56
|
- lib/prak/file.rb
|
|
56
57
|
- lib/prak/search.rb
|
|
57
58
|
- prak.gemspec
|