utils 0.2.4 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/classify +15 -3
- data/bin/discover +25 -10
- data/bin/edit +16 -9
- data/bin/probe +36 -11
- data/bin/search +87 -8
- data/lib/utils.rb +4 -1
- data/lib/utils/finder.rb +0 -3
- data/lib/utils/grepper.rb +6 -13
- data/lib/utils/irb.rb +78 -182
- data/lib/utils/irb/service.rb +39 -0
- data/lib/utils/line_formatter.rb +162 -103
- data/lib/utils/patterns.rb +2 -0
- data/lib/utils/probe_server.rb +62 -82
- data/lib/utils/version.rb +1 -1
- data/utils.gemspec +12 -12
- data/utils.gemspec +0 -0
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27961e1f6195cb69054f6b658820b1544d33ab46
|
4
|
+
data.tar.gz: e0a540a6f1cb21602322d8741a349212c9330882
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f13ebaa7a97cc7a8067f63149a3ecccfedf237686cdd7864cddee1e8d52fba0e411a0329fb3eb8a764c593cfb49aed8943167c74bb0ed546802511b2b36acda5
|
7
|
+
data.tar.gz: 81efb168bb27cd2498147c6b48f18dad0714a575dd4d516d021acd57817a2b8072d1a297890cf172bf93efb807a4879542b8166dd28c5c12e7b9528d385ef1db
|
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ GemHadar do
|
|
15
15
|
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', '.AppleDouble', 'tags', '.bundle'
|
16
16
|
readme 'README.md'
|
17
17
|
|
18
|
-
dependency 'tins', '~>1.
|
18
|
+
dependency 'tins', '~>1.8'
|
19
19
|
dependency 'term-ansicolor', '~>1.3'
|
20
20
|
dependency 'pstree', '~>0.1'
|
21
21
|
dependency 'pry-editline'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.4
|
data/bin/classify
CHANGED
@@ -4,23 +4,35 @@ require 'tins/go'
|
|
4
4
|
include Tins::GO
|
5
5
|
require 'tins/xt/string'
|
6
6
|
|
7
|
-
$opts = go '
|
7
|
+
$opts = go 'bdtsn:'
|
8
8
|
|
9
9
|
string = ARGV.shift or fail "need a class/filepath/filename"
|
10
10
|
|
11
|
+
def path_shifter(string, separator: ?/, n: 0)
|
12
|
+
n or return string
|
13
|
+
n, path = n.to_i, string.split(separator)
|
14
|
+
if n < 0
|
15
|
+
path = path.slice(n..-1)
|
16
|
+
else
|
17
|
+
path.slice!(0...n)
|
18
|
+
end
|
19
|
+
path * separator
|
20
|
+
end
|
21
|
+
|
11
22
|
def underscore(string)
|
12
|
-
string = string
|
23
|
+
string = path_shifter(string, n: $opts['n'], separator: '::')
|
13
24
|
string = string.underscore
|
14
25
|
$opts['s'] and string << '.rb'
|
15
26
|
print string
|
16
27
|
end
|
17
28
|
|
18
29
|
def camelize(string)
|
19
|
-
string =
|
30
|
+
string = path_shifter(string, n: $opts['n'])
|
20
31
|
string = string.gsub(/#{Regexp.quote(File.extname(string))}\Z/, '')
|
21
32
|
print string.camelize
|
22
33
|
end
|
23
34
|
|
35
|
+
$opts['b'] and $opts['n'] = '-1'
|
24
36
|
case
|
25
37
|
when $opts['t']
|
26
38
|
if string[0, 1] =~ /[A-Z]/
|
data/bin/discover
CHANGED
@@ -2,14 +2,24 @@
|
|
2
2
|
|
3
3
|
require 'utils'
|
4
4
|
include Utils
|
5
|
-
require 'tins/
|
5
|
+
require 'tins/xt'
|
6
6
|
include Tins::GO
|
7
7
|
|
8
|
-
def edit_files(paths)
|
9
|
-
editor = Utils::Editor.new
|
10
|
-
|
8
|
+
def edit_files(paths, pick: false)
|
9
|
+
editor = Utils::Editor.new
|
10
|
+
if pick
|
11
|
+
if paths.size > 1
|
12
|
+
path = complete(prompt: 'Pick? ') do |p|
|
13
|
+
paths.grep /#{p}/
|
14
|
+
end
|
15
|
+
else
|
16
|
+
path = paths.first
|
17
|
+
end
|
18
|
+
editor.edit(path.strip)
|
19
|
+
else
|
20
|
+
editor.wait = true
|
21
|
+
editor.edit(*paths)
|
11
22
|
end
|
12
|
-
editor.edit(*paths)
|
13
23
|
end
|
14
24
|
|
15
25
|
def usage
|
@@ -27,6 +37,7 @@ Options are
|
|
27
37
|
-c disable color output
|
28
38
|
-i use case insensitive matches
|
29
39
|
-e open the matching files with edit command
|
40
|
+
-E pick one file to edit
|
30
41
|
-a CSET use only character set CSET from PATTERN
|
31
42
|
-I SUFFIX only include files with suffix SUFFIX during finding
|
32
43
|
-b match also binary files
|
@@ -38,7 +49,7 @@ Version is #{File.basename($0)} #{Utils::VERSION}.
|
|
38
49
|
exit 1
|
39
50
|
end
|
40
51
|
|
41
|
-
args = go 'I:a:
|
52
|
+
args = go 'I:a:rdDcieEbvh'
|
42
53
|
args['h'] and usage
|
43
54
|
pattern = ARGV.shift or usage
|
44
55
|
roots = (ARGV.empty? ? [ Dir.pwd ] : ARGV).map { |f| File.expand_path(f) }
|
@@ -53,9 +64,13 @@ finder = Finder.new(
|
|
53
64
|
:args => args,
|
54
65
|
:roots => roots,
|
55
66
|
:config => config
|
56
|
-
).search
|
57
|
-
|
58
|
-
|
59
|
-
|
67
|
+
).search
|
68
|
+
|
69
|
+
case
|
70
|
+
when args['E']
|
71
|
+
edit_files finder.paths, pick: true
|
72
|
+
when args['e']
|
60
73
|
edit_files finder.paths
|
74
|
+
else
|
75
|
+
puts finder.paths
|
61
76
|
end
|
data/bin/edit
CHANGED
@@ -14,21 +14,22 @@ PATHS are the directory and file paths that are opened in the vim.
|
|
14
14
|
|
15
15
|
Options are
|
16
16
|
|
17
|
-
-w
|
18
|
-
-s
|
19
|
-
-m
|
20
|
-
-c
|
21
|
-
-
|
22
|
-
-
|
23
|
-
-
|
24
|
-
-
|
17
|
+
-w open a buffer in vim and wait until it is deleted
|
18
|
+
-s read files and files:linenumbers from stdin and open them
|
19
|
+
-m make intermediate non existing directories to file
|
20
|
+
-g [m|c|d|o|g] open modified/cached/deleted/other/(next git commit) files
|
21
|
+
-c COMMAND send ex command to the current running editor
|
22
|
+
-C COMMAND send visual command to the current running editor
|
23
|
+
-p DURATION pause for this many seconds to wait for vim's reaction
|
24
|
+
-S SERVER specify the server for this edit command
|
25
|
+
-h display this help
|
25
26
|
|
26
27
|
Version is #{File.basename($0)} #{Utils::VERSION}.
|
27
28
|
EOT
|
28
29
|
exit 1
|
29
30
|
end
|
30
31
|
|
31
|
-
$opt = go 'p:S:c:wsmh'
|
32
|
+
$opt = go 'p:S:c:g:wsmh'
|
32
33
|
$opt['h'] and usage
|
33
34
|
|
34
35
|
config = Utils::Config::ConfigFile.new
|
@@ -70,6 +71,12 @@ if argv.empty?
|
|
70
71
|
argv << file.path
|
71
72
|
end
|
72
73
|
end
|
74
|
+
case git_files_arg = $opt['g']
|
75
|
+
when ?g
|
76
|
+
argv.concat `git diff HEAD --name-only`.lines.map(&:chomp).uniq
|
77
|
+
when /\A[mcdo]\z/
|
78
|
+
argv.concat `git ls-files -#{git_files_arg}`.lines.map(&:chomp).uniq
|
79
|
+
end
|
73
80
|
if argv.empty?
|
74
81
|
editor.start
|
75
82
|
else
|
data/bin/probe
CHANGED
@@ -10,15 +10,16 @@ require 'drb'
|
|
10
10
|
|
11
11
|
def usage
|
12
12
|
puts <<-EOT
|
13
|
-
Usage: #{File.basename($0)} [OPTS] FILENAME[:LINENO]
|
13
|
+
Usage: #{File.basename($0)} [OPTS] [FILENAME[:LINENO]]
|
14
14
|
|
15
15
|
Options are
|
16
16
|
|
17
17
|
-n TESTNAME run the test TESTNAME in file FILENAME
|
18
18
|
-t FRAMEWORK use test framework FRAMEWORK (rspec, test-unit or cucumber)
|
19
19
|
-c start probe as a client
|
20
|
+
-C FOO[=BAR] set/get env variable on probe server
|
20
21
|
-l start probe as a server
|
21
|
-
-
|
22
|
+
-u URI use this DRb URI communication
|
22
23
|
-h display this help
|
23
24
|
|
24
25
|
Version is #{File.basename($0)} #{Utils::VERSION}.
|
@@ -43,8 +44,20 @@ singleton_class.class_eval do
|
|
43
44
|
memoize_function :zeus?
|
44
45
|
end
|
45
46
|
|
47
|
+
def spring?
|
48
|
+
`bin/spring status`.lines.first =~ /^Spring is running:/
|
49
|
+
rescue Errno::ENOENT
|
50
|
+
false
|
51
|
+
end
|
52
|
+
singleton_class.class_eval do
|
53
|
+
memoize_function :spring?
|
54
|
+
end
|
55
|
+
|
46
56
|
def start_server
|
47
57
|
Thread.abort_on_exception = $DEBUG
|
58
|
+
spring? and
|
59
|
+
puts "Found spring running, I'll try to use it for running tests."
|
60
|
+
|
48
61
|
zeus? and
|
49
62
|
puts "Found a zeus socket file, I'll try to use it for running tests."
|
50
63
|
|
@@ -58,10 +71,18 @@ def start_server
|
|
58
71
|
end
|
59
72
|
|
60
73
|
def connect_server
|
61
|
-
Utils::ProbeServer::Job.colorize = true
|
62
|
-
puts "Connecting probe server on #{$uri.inspect}."
|
63
74
|
DRb.start_service
|
64
75
|
probe_server = DRbObject.new_with_uri($uri)
|
76
|
+
if setting = $opt['C']
|
77
|
+
case setting
|
78
|
+
when /\A([^=]+)=([^=]+)\z/
|
79
|
+
probe_server.env[$1] = $2
|
80
|
+
when /\A([^=]+)\z/
|
81
|
+
puts probe_server.env[$1]
|
82
|
+
else
|
83
|
+
usage
|
84
|
+
end
|
85
|
+
end
|
65
86
|
if $opt['c']
|
66
87
|
opts = $opt.subhash('n', 't').each_with_object([]) { |(k, v), a|
|
67
88
|
v.full? and a.concat [ "-#{k}", v ]
|
@@ -80,28 +101,32 @@ if i = ARGV.index('--')
|
|
80
101
|
else
|
81
102
|
$args = ARGV.dup
|
82
103
|
end
|
83
|
-
$opt = go '
|
104
|
+
$opt = go 'lct:n:u:C:h', $args
|
84
105
|
$opt['h'] and usage
|
85
106
|
|
86
|
-
$uri =
|
107
|
+
$uri = $opt['u'] || 'drbunix:probe.socket'
|
87
108
|
|
88
109
|
case
|
89
110
|
when $opt['l']
|
90
111
|
start_server
|
91
112
|
exit
|
92
|
-
when $opt['c']
|
113
|
+
when $opt['c'], $opt['C']
|
93
114
|
connect_server
|
94
115
|
end
|
95
116
|
|
96
|
-
$args.empty? and
|
117
|
+
$args.empty? and exit
|
97
118
|
puts "Running tests in #{$args.inspect}"
|
98
119
|
|
99
120
|
case ($opt['t'] || $config.probe.test_framework).to_sym
|
100
121
|
when :rspec
|
101
|
-
|
102
|
-
|
122
|
+
case
|
123
|
+
when spring?
|
124
|
+
rspec = %w[bin/spring rspec -rutils -f Utils::LineFormatter ]
|
125
|
+
when zeus?
|
126
|
+
rspec = %w[-S zeus rspec -rutils -f Utils::LineFormatter ]
|
103
127
|
else
|
104
|
-
rspec = [ find_cmd('rspec', 'spec') ] << '-
|
128
|
+
rspec = [ find_cmd('rspec', 'spec') ] << '-rutils' << '-f' <<
|
129
|
+
'Utils::LineFormatter'
|
105
130
|
end
|
106
131
|
if linenumber = $opt['n']
|
107
132
|
cmd 'ruby', '-I', $config.probe.include_dirs_argument, *rspec, '-l',
|
data/bin/search
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
|
4
4
|
require 'utils'
|
5
5
|
include Utils
|
6
|
-
require 'tins/
|
6
|
+
require 'tins/xt'
|
7
7
|
include Tins::GO
|
8
|
+
require 'term/ansicolor'
|
9
|
+
include Term::ANSIColor
|
8
10
|
|
9
11
|
def convert_ruby_to_vim_regexp(pattern)
|
10
12
|
regexp = pattern.source.dup
|
@@ -13,14 +15,87 @@ def convert_ruby_to_vim_regexp(pattern)
|
|
13
15
|
regexp
|
14
16
|
end
|
15
17
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
18
|
+
def read_line(path)
|
19
|
+
filename, lineno = path.source_location
|
20
|
+
line = File.open(filename) do |file|
|
21
|
+
file.lazy.each_with_index.select { |l, n| n + 1 == lineno }.first&.first
|
19
22
|
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def replace_line(path, new_line)
|
26
|
+
filename, lineno = path.source_location
|
27
|
+
File.secure_write filename do |output|
|
28
|
+
File.open(filename) do |file|
|
29
|
+
file.each_with_index do |line, n|
|
30
|
+
if n + 1 == lineno
|
31
|
+
output.write new_line
|
32
|
+
else
|
33
|
+
output.write line
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def replace_ask(editor, path, pattern, replace, all)
|
41
|
+
line = read_line path
|
42
|
+
display_new_line = line.gsub(
|
43
|
+
pattern.matcher,
|
44
|
+
"#{on_red(line[pattern.matcher])}#{on_green(replace)}"
|
45
|
+
)
|
46
|
+
loop do
|
47
|
+
puts red(path)
|
48
|
+
puts display_new_line
|
49
|
+
if all
|
50
|
+
new_line = line.gsub(pattern.matcher, replace)
|
51
|
+
replace_line path, new_line
|
52
|
+
break true
|
53
|
+
else
|
54
|
+
print "Replace? (#{bold(?y)}/n/e/a) "
|
55
|
+
case answer = STDIN.gets.chomp
|
56
|
+
when ?y, '', ?a
|
57
|
+
new_line = line.gsub(pattern.matcher, replace)
|
58
|
+
replace_line path, new_line
|
59
|
+
break answer == ?a
|
60
|
+
when ?n
|
61
|
+
break false
|
62
|
+
when ?e
|
63
|
+
editor.edit(path.strip)
|
64
|
+
break false
|
65
|
+
when ?a
|
66
|
+
break true
|
67
|
+
else
|
68
|
+
next
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def edit_files(pattern, paths, pick: false, replace: nil)
|
75
|
+
editor = Utils::Editor.new
|
20
76
|
editor.edit_remote_send("<ESC>/#{convert_ruby_to_vim_regexp(pattern)}<CR>")
|
21
|
-
|
22
|
-
|
23
|
-
editor.
|
77
|
+
case
|
78
|
+
when replace
|
79
|
+
editor.wait = true
|
80
|
+
all = false
|
81
|
+
for path in paths
|
82
|
+
all |= replace_ask editor, path, pattern, replace, all
|
83
|
+
end
|
84
|
+
when pick
|
85
|
+
if paths.size > 1
|
86
|
+
path = complete(prompt: 'Pick? ') do |p|
|
87
|
+
paths.grep /#{p}/
|
88
|
+
end
|
89
|
+
else
|
90
|
+
path = paths.first
|
91
|
+
end
|
92
|
+
editor.edit(path.strip)
|
93
|
+
else
|
94
|
+
editor.wait = true
|
95
|
+
for path in paths
|
96
|
+
STDERR.puts "Edit #{path}"
|
97
|
+
editor.edit(path)
|
98
|
+
end
|
24
99
|
end
|
25
100
|
end
|
26
101
|
|
@@ -48,6 +123,8 @@ Options are
|
|
48
123
|
-i use case insensitive matches
|
49
124
|
-I SUFFIX only include files with suffix SUFFIX in search
|
50
125
|
-e open the matching files with edit command
|
126
|
+
-E pick one file to edit
|
127
|
+
-r REPLACE replace the searched match with REPLACE
|
51
128
|
-a CSET use only character set CSET from PATTERN
|
52
129
|
-v be verbose
|
53
130
|
-h display this help
|
@@ -57,7 +134,7 @@ Version is #{File.basename($0)} #{Utils::VERSION}.
|
|
57
134
|
exit 1
|
58
135
|
end
|
59
136
|
|
60
|
-
args = go 'I:A:B:C:s:S:n:N:a:
|
137
|
+
args = go 'r:I:A:B:C:s:S:n:N:a:RciflLeEvh'
|
61
138
|
args['h'] and usage
|
62
139
|
pattern = ARGV.shift or usage
|
63
140
|
roots = (ARGV.empty? ? [ Dir.pwd ] : ARGV).map { |f| File.expand_path(f) }
|
@@ -73,6 +150,8 @@ grepper = Grepper.new(
|
|
73
150
|
:config => config
|
74
151
|
).search
|
75
152
|
case
|
153
|
+
when args['r'] then edit_files grepper.pattern, grepper.paths, replace: args['r']
|
154
|
+
when args['E'] then edit_files grepper.pattern, grepper.paths, pick: true
|
76
155
|
when args['e'] then edit_files grepper.pattern, grepper.paths
|
77
156
|
when args['l'] then puts grepper.paths
|
78
157
|
end
|
data/lib/utils.rb
CHANGED
@@ -10,8 +10,11 @@ module Utils
|
|
10
10
|
require 'utils/grepper'
|
11
11
|
require 'utils/probe_server'
|
12
12
|
require 'utils/ssh_tunnel_specification'
|
13
|
-
require 'utils/line_formatter'
|
14
13
|
require 'utils/line_blamer'
|
14
|
+
begin
|
15
|
+
require 'utils/line_formatter'
|
16
|
+
rescue LoadError
|
17
|
+
end
|
15
18
|
|
16
19
|
require 'utils/xt/source_location_extension'
|
17
20
|
class ::Object
|
data/lib/utils/finder.rb
CHANGED
data/lib/utils/grepper.rb
CHANGED
@@ -94,7 +94,7 @@ class Utils::Grepper
|
|
94
94
|
end
|
95
95
|
unless @output.empty?
|
96
96
|
case
|
97
|
-
when @args['l'], @args['e']
|
97
|
+
when @args['l'], @args['e'], @args['E'], @args['r']
|
98
98
|
@output.uniq!
|
99
99
|
@paths.concat @output
|
100
100
|
else
|
@@ -111,11 +111,12 @@ class Utils::Grepper
|
|
111
111
|
@skip_pattern and @skip_pattern =~ line and next
|
112
112
|
line[m.begin(0)...m.end(0)] = black on_white m[0]
|
113
113
|
@queue and @queue << line
|
114
|
-
|
114
|
+
case
|
115
|
+
when @args['l']
|
115
116
|
@output << @filename
|
116
|
-
|
117
|
+
when @args['L'], @args['r']
|
117
118
|
@output << "#{@filename}:#{file.lineno}"
|
118
|
-
|
119
|
+
when @args['e'], @args['E']
|
119
120
|
@output << "#{@filename}:#{file.lineno}"
|
120
121
|
break
|
121
122
|
else
|
@@ -149,15 +150,7 @@ class Utils::Grepper
|
|
149
150
|
find(*(@roots + [ { :suffix => suffixes } ])) do |filename|
|
150
151
|
match(filename)
|
151
152
|
end
|
152
|
-
|
153
|
-
@paths = @paths.sort_by do |path|
|
154
|
-
pair = path.split(':')
|
155
|
-
pair[1] = pair[1].to_i
|
156
|
-
pair
|
157
|
-
end
|
158
|
-
else
|
159
|
-
@paths.sort!
|
160
|
-
end
|
153
|
+
@paths = @paths.sort_by(&:source_location)
|
161
154
|
self
|
162
155
|
end
|
163
156
|
end
|