utils 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +68 -0
- data/VERSION +1 -0
- data/bin/chroot-exec +12 -0
- data/bin/chroot-libs +18 -0
- data/bin/classify +37 -0
- data/bin/discover +137 -0
- data/bin/edit +74 -0
- data/bin/errf +32 -0
- data/bin/git-empty +8 -0
- data/bin/myex +90 -0
- data/bin/number_files +26 -0
- data/bin/same_files +37 -0
- data/bin/search +205 -0
- data/bin/sedit +3 -0
- data/bin/sshscreen +68 -0
- data/bin/term +21 -0
- data/bin/unquarantine_apps +8 -0
- data/bin/untest +17 -0
- data/bin/utils-install-config +10 -0
- data/bin/vacuum_firefox_sqlite +22 -0
- data/bin/xmp +74 -0
- data/lib/utils.rb +8 -0
- data/lib/utils/config.rb +23 -0
- data/lib/utils/config/gdb/asm +179 -0
- data/lib/utils/config/gdb/ruby +528 -0
- data/lib/utils/config/gdbinit +8 -0
- data/lib/utils/config/irbrc +455 -0
- data/lib/utils/config/rdebugrc +2 -0
- data/lib/utils/config/screenrc +143 -0
- data/lib/utils/config/vim/autoload/Align.vim +1029 -0
- data/lib/utils/config/vim/autoload/AlignMaps.vim +330 -0
- data/lib/utils/config/vim/autoload/rails.vim +4744 -0
- data/lib/utils/config/vim/autoload/rubycomplete.vim +801 -0
- data/lib/utils/config/vim/autoload/sqlcomplete.vim +741 -0
- data/lib/utils/config/vim/autoload/vimball.vim +750 -0
- data/lib/utils/config/vim/colors/flori.vim +113 -0
- data/lib/utils/config/vim/compiler/eruby.vim +40 -0
- data/lib/utils/config/vim/compiler/ruby.vim +67 -0
- data/lib/utils/config/vim/compiler/rubyunit.vim +34 -0
- data/lib/utils/config/vim/ftdetect/ragel.vim +2 -0
- data/lib/utils/config/vim/ftdetect/ruby.vim +17 -0
- data/lib/utils/config/vim/ftplugin/eruby.vim +100 -0
- data/lib/utils/config/vim/ftplugin/ruby.vim +260 -0
- data/lib/utils/config/vim/ftplugin/xml.vim +941 -0
- data/lib/utils/config/vim/indent/IndentAnything_html.vim +35 -0
- data/lib/utils/config/vim/indent/eruby.vim +77 -0
- data/lib/utils/config/vim/indent/javascript.vim +116 -0
- data/lib/utils/config/vim/indent/ruby.vim +377 -0
- data/lib/utils/config/vim/plugin/AlignMapsPlugin.vim +242 -0
- data/lib/utils/config/vim/plugin/AlignPlugin.vim +41 -0
- data/lib/utils/config/vim/plugin/Decho.vim +592 -0
- data/lib/utils/config/vim/plugin/IndentAnything.vim +675 -0
- data/lib/utils/config/vim/plugin/bufexplorer.vim +1144 -0
- data/lib/utils/config/vim/plugin/cecutil.vim +482 -0
- data/lib/utils/config/vim/plugin/fugitive.vim +1703 -0
- data/lib/utils/config/vim/plugin/lusty-explorer.vim +1509 -0
- data/lib/utils/config/vim/plugin/rails.vim +340 -0
- data/lib/utils/config/vim/plugin/rubyextra.vim +193 -0
- data/lib/utils/config/vim/plugin/surround.vim +628 -0
- data/lib/utils/config/vim/plugin/taglist.vim +4546 -0
- data/lib/utils/config/vim/plugin/test/IndentAnything/test.js +131 -0
- data/lib/utils/config/vim/plugin/vimballPlugin.vim +40 -0
- data/lib/utils/config/vim/syntax/Decho.vim +101 -0
- data/lib/utils/config/vim/syntax/eruby.vim +73 -0
- data/lib/utils/config/vim/syntax/javascript.vim +246 -0
- data/lib/utils/config/vim/syntax/ragel.vim +165 -0
- data/lib/utils/config/vim/syntax/ruby.vim +367 -0
- data/lib/utils/config/vimrc +461 -0
- data/lib/utils/file.rb +49 -0
- data/lib/utils/find.rb +54 -0
- data/lib/utils/md5.rb +23 -0
- data/lib/utils/patterns.rb +34 -0
- data/lib/utils/version.rb +8 -0
- data/utils.gemspec +33 -0
- metadata +183 -0
@@ -0,0 +1,455 @@
|
|
1
|
+
# vim: set filetype=ruby et sw=2 ts=2:
|
2
|
+
|
3
|
+
# Some libraries I just don't want to miss in my irb session.
|
4
|
+
require 'irb/completion'
|
5
|
+
require 'enumerator'
|
6
|
+
require 'pp'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'find'
|
9
|
+
include FileUtils
|
10
|
+
begin
|
11
|
+
require 'ap'
|
12
|
+
rescue LoadError
|
13
|
+
end
|
14
|
+
|
15
|
+
$pager = ENV['PAGER'] || 'less -r'
|
16
|
+
|
17
|
+
class Symbol
|
18
|
+
def to_proc
|
19
|
+
Proc.new do |obj, *args|
|
20
|
+
obj.__send__(self, *args)
|
21
|
+
end
|
22
|
+
end unless method_defined?(:to_proc)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Start _ri_ for +pattern+. If +pattern+ is not string like, call it with
|
26
|
+
# pattern.class.name as argument.
|
27
|
+
def ri(*patterns)
|
28
|
+
patterns.map! { |p| p.respond_to?(:to_str) ? p.to_str : p.class.name }
|
29
|
+
system "ri #{patterns.map { |p| "'#{p}'" } * ' '} | #{$pager}"
|
30
|
+
end
|
31
|
+
|
32
|
+
class Module
|
33
|
+
# Start +ri+ for +module#pattern+, trying to find a method matching +pattern+
|
34
|
+
# for all modules in the ancestors chain of this module.
|
35
|
+
def ri(pattern = nil)
|
36
|
+
if pattern
|
37
|
+
pattern = pattern.to_sym.to_s if pattern.respond_to? :to_sym
|
38
|
+
ancestors.each do |a|
|
39
|
+
if method = a.instance_methods(false).find { |m| pattern === m }
|
40
|
+
a = Object if a == Kernel # ri seems to be confused
|
41
|
+
system "ri #{a}##{method} | #{$pager}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
else
|
45
|
+
system "ri #{self} | #{$pager}"
|
46
|
+
end
|
47
|
+
return
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Restart this irb.
|
52
|
+
def irb_restart
|
53
|
+
exec $0
|
54
|
+
end
|
55
|
+
|
56
|
+
# Return all instance methods of obj's class.
|
57
|
+
def irb_all_class_instance_methods(obj)
|
58
|
+
methods = obj.class.instance_methods
|
59
|
+
irb_wrap_methods obj, methods
|
60
|
+
end
|
61
|
+
|
62
|
+
# Return instance methods of obj's class without the inherited/mixed in
|
63
|
+
# methods.
|
64
|
+
def irb_class_instance_methods(obj)
|
65
|
+
methods = obj.class.instance_methods(false)
|
66
|
+
irb_wrap_methods obj, methods
|
67
|
+
end
|
68
|
+
|
69
|
+
# Return all instance methods defined in module modul.
|
70
|
+
def irb_all_instance_methods(modul)
|
71
|
+
methods = modul.instance_methods
|
72
|
+
irb_wrap_methods modul, methods, true
|
73
|
+
end
|
74
|
+
|
75
|
+
# Return instance methods defined in module modul without the inherited/mixed
|
76
|
+
# in methods.
|
77
|
+
def irb_instance_methods(modul)
|
78
|
+
methods = modul.instance_methods(false)
|
79
|
+
irb_wrap_methods modul, methods, true
|
80
|
+
end
|
81
|
+
|
82
|
+
# Return all methods of obj (including obj's eigenmethods.)
|
83
|
+
def irb_all_methods(obj)
|
84
|
+
methods = obj.methods
|
85
|
+
irb_wrap_methods obj, methods
|
86
|
+
end
|
87
|
+
|
88
|
+
# Return instance methods of obj's class without the inherited/mixed in
|
89
|
+
# methods, but including obj's eigenmethods.
|
90
|
+
def irb_methods(obj)
|
91
|
+
methods = obj.class.ancestors[1..-1].inject(obj.methods) do |all, a|
|
92
|
+
all -= a.instance_methods
|
93
|
+
end
|
94
|
+
irb_wrap_methods obj, methods
|
95
|
+
end
|
96
|
+
|
97
|
+
# Return all eigen methods of obj.
|
98
|
+
def irb_eigen_methods(obj)
|
99
|
+
irb_wrap_methods obj, obj.methods(false)
|
100
|
+
end
|
101
|
+
|
102
|
+
def irb_wrap_methods(obj, methods, modul = false)
|
103
|
+
methods.map do |name|
|
104
|
+
MethodWrapper.new(obj, name, modul)
|
105
|
+
end.sort!
|
106
|
+
end
|
107
|
+
|
108
|
+
class WrapperBase
|
109
|
+
include Comparable
|
110
|
+
|
111
|
+
def initialize(name)
|
112
|
+
@name =
|
113
|
+
case
|
114
|
+
when name.respond_to?(:to_str)
|
115
|
+
name.to_str
|
116
|
+
when name.respond_to?(:to_sym)
|
117
|
+
name.to_sym.to_s
|
118
|
+
else
|
119
|
+
name.to_s
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
attr_reader :name
|
124
|
+
|
125
|
+
attr_reader :description
|
126
|
+
|
127
|
+
alias to_str name
|
128
|
+
|
129
|
+
alias inspect description
|
130
|
+
|
131
|
+
alias to_s description
|
132
|
+
|
133
|
+
def ==(name)
|
134
|
+
@name = name
|
135
|
+
end
|
136
|
+
|
137
|
+
alias eql? ==
|
138
|
+
|
139
|
+
def hash
|
140
|
+
@name.hash
|
141
|
+
end
|
142
|
+
|
143
|
+
def <=>(other)
|
144
|
+
@name <=> other.name
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
class MethodWrapper < WrapperBase
|
149
|
+
def initialize(obj, name, modul)
|
150
|
+
super(name)
|
151
|
+
if modul
|
152
|
+
@arity = obj.instance_method(name).arity
|
153
|
+
else
|
154
|
+
@arity = obj.method(name).arity
|
155
|
+
end
|
156
|
+
@description = "#@name(#@arity)"
|
157
|
+
end
|
158
|
+
|
159
|
+
attr_reader :arity
|
160
|
+
end
|
161
|
+
|
162
|
+
class ConstantWrapper < WrapperBase
|
163
|
+
def initialize(obj, name)
|
164
|
+
super(name)
|
165
|
+
@klass = obj.class
|
166
|
+
@description = "#@name:#@klass"
|
167
|
+
end
|
168
|
+
|
169
|
+
attr_reader :klass
|
170
|
+
end
|
171
|
+
|
172
|
+
# Return all the constants defined in +modul+.
|
173
|
+
def irb_constants(modul)
|
174
|
+
modul.constants.map { |c| ConstantWrapper.new(modul.const_get(c), c) }.sort
|
175
|
+
end
|
176
|
+
|
177
|
+
# Return all the subclasses of +klass+. TODO implement subclasses w/out rails
|
178
|
+
def irb_subclasses(klass)
|
179
|
+
klass.subclasses.map { |c| ConstantWrapper.new(eval(c), c) }.sort
|
180
|
+
end
|
181
|
+
|
182
|
+
unless Object.const_defined?(:Infinity)
|
183
|
+
Infinity = 1.0 / 0 # I like to define the infinite.
|
184
|
+
end
|
185
|
+
|
186
|
+
# Output all kinds of information about +obj+. If detailed is given output
|
187
|
+
# details about the methods (+ arity) in inheritance chain of +obj+ as well.
|
188
|
+
# * detailed as 0 output instance methods only of part 0 (the first) of the
|
189
|
+
# chain.
|
190
|
+
# * detailed as 1..2 output instance methods of +obj+ inherited from parts 1
|
191
|
+
# and 2 of the the chain.
|
192
|
+
def irb_info(obj, detailed = nil)
|
193
|
+
if Module === obj
|
194
|
+
modul = obj
|
195
|
+
klassp = Class === modul
|
196
|
+
if klassp
|
197
|
+
obj = modul.allocate
|
198
|
+
end
|
199
|
+
else
|
200
|
+
modul = obj.class
|
201
|
+
end
|
202
|
+
inspected = obj.inspect
|
203
|
+
puts "obj = #{inspected.size > 40 ? inspected[0, 40] + '...' : inspected} is of class #{obj.class}."
|
204
|
+
am = irb_all_methods(obj).size
|
205
|
+
ms = irb_methods(obj).size
|
206
|
+
ems = irb_eigen_methods(obj).size
|
207
|
+
puts "obj: #{am} methods, #{ms} only local#{ems > 0 ? " (#{ems} eigenmethods),": ','} #{am - ms} inherited/mixed in."
|
208
|
+
acim = irb_all_class_instance_methods(obj).size
|
209
|
+
cim = irb_class_instance_methods(obj).size
|
210
|
+
puts "obj: #{acim} instance methods, #{cim} local, #{acim - cim} only inherited/mixed in."
|
211
|
+
if klassp
|
212
|
+
s = modul.superclass
|
213
|
+
puts "Superclass of #{modul}: #{s}"
|
214
|
+
end
|
215
|
+
a = []
|
216
|
+
ec = true
|
217
|
+
begin
|
218
|
+
a << (class << obj; self; end)
|
219
|
+
rescue TypeError
|
220
|
+
ec = false
|
221
|
+
end
|
222
|
+
a.concat modul.ancestors
|
223
|
+
if ec
|
224
|
+
puts "Ancestors of #{modul}: (#{a[0]},) #{a[1..-1].map { |k| "#{k}#{k == s ? '*' : ''}" } * ', '}"
|
225
|
+
else
|
226
|
+
puts "Ancestors of #{modul}: #{a[0..-1].map { |k| "#{k}#{k == s ? '*' : ''}" } * ', '}"
|
227
|
+
end
|
228
|
+
if Class === modul and detailed
|
229
|
+
if detailed.respond_to? :to_int
|
230
|
+
detailed = detailed..detailed
|
231
|
+
end
|
232
|
+
detailed.each do |i|
|
233
|
+
break if i >= a.size
|
234
|
+
k = a[i]
|
235
|
+
puts "#{k}:"
|
236
|
+
puts irb_wrap_methods(obj, k.instance_methods(false)).sort
|
237
|
+
end
|
238
|
+
end
|
239
|
+
nil
|
240
|
+
end
|
241
|
+
|
242
|
+
# Output *all* the irb_info about +obj+. You may need to buy a bigger screen for
|
243
|
+
# this or use:
|
244
|
+
# less { irb_fullinfo object }
|
245
|
+
def irb_fullinfo(obj)
|
246
|
+
irb_info obj, 0..Infinity
|
247
|
+
end
|
248
|
+
|
249
|
+
def capture_output(with_stderr = false)
|
250
|
+
return "missing block" unless block_given?
|
251
|
+
require 'tempfile'
|
252
|
+
begin
|
253
|
+
old_stdout, $stdout = $stdout, Tempfile.new('irb')
|
254
|
+
if with_stderr
|
255
|
+
old_stderr, $stderr = $stderr, $stdout
|
256
|
+
end
|
257
|
+
yield
|
258
|
+
ensure
|
259
|
+
$stdout, temp = old_stdout, $stdout
|
260
|
+
with_stderr and $stderr = old_stderr
|
261
|
+
end
|
262
|
+
temp.rewind
|
263
|
+
temp.read
|
264
|
+
end
|
265
|
+
|
266
|
+
# Use pager on the output of the commands given in the block.
|
267
|
+
def less(with_stderr = false, &block)
|
268
|
+
IO.popen($pager, 'w') do |f|
|
269
|
+
f.write capture_output(with_stderr, &block)
|
270
|
+
f.close_write
|
271
|
+
end
|
272
|
+
nil
|
273
|
+
end
|
274
|
+
|
275
|
+
class String
|
276
|
+
# Pipe this string into +cmd+.
|
277
|
+
def |(cmd)
|
278
|
+
IO.popen(cmd, 'w+') do |f|
|
279
|
+
f.write self
|
280
|
+
f.close_write
|
281
|
+
return f.read
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
# Write this string into file +filename+.
|
286
|
+
def >>(filename)
|
287
|
+
irb_write(filename, self)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
def irb_time
|
292
|
+
s = Time.now
|
293
|
+
yield
|
294
|
+
d = Time.now - s
|
295
|
+
warn "Took %.3fs seconds." % d
|
296
|
+
d
|
297
|
+
end
|
298
|
+
|
299
|
+
def irb_time_tap
|
300
|
+
r = nil
|
301
|
+
irb_time { r = yield }
|
302
|
+
r
|
303
|
+
end
|
304
|
+
|
305
|
+
def irb_time_watch(duration = 1)
|
306
|
+
start = Time.now
|
307
|
+
pre = nil
|
308
|
+
loop do
|
309
|
+
cur = [ yield ].flatten
|
310
|
+
unless pre
|
311
|
+
pre = cur.map(&:to_f)
|
312
|
+
cur = [ yield ].flatten
|
313
|
+
end
|
314
|
+
expired = Time.now - start
|
315
|
+
diffs = cur.zip(pre).map { |c, p| c - p }
|
316
|
+
rates = diffs.map { |d| d / duration }
|
317
|
+
warn "#{expired} #{cur.zip(rates, diffs).map(&:inspect) * ' '} # / per sec."
|
318
|
+
pre = cur.map(&:to_f)
|
319
|
+
sleep duration
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
def irb_write(filename, text = nil)
|
324
|
+
if block_given?
|
325
|
+
text = yield
|
326
|
+
else
|
327
|
+
text or raise "need a text as argument or as a block return value"
|
328
|
+
end
|
329
|
+
open(filename, 'wb') { |f| f.write text }
|
330
|
+
end
|
331
|
+
|
332
|
+
def irb_read(filename, chunk_size = 8_192)
|
333
|
+
if block_given?
|
334
|
+
File.open(filename) do |file|
|
335
|
+
until file.eof?
|
336
|
+
yield file.read(chunk_size)
|
337
|
+
end
|
338
|
+
end
|
339
|
+
else
|
340
|
+
IO.read filename
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
def irb_load_each(*files)
|
345
|
+
files = files.map { |f| f.gsub(/(\.rb)?\Z/, '.rb') }
|
346
|
+
for file in files
|
347
|
+
Find.find('.') do |f|
|
348
|
+
if file == File.basename(f)
|
349
|
+
load f
|
350
|
+
STDERR.puts "Loaded '#{f}'."
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
nil
|
355
|
+
end
|
356
|
+
|
357
|
+
def irb_edit(*files)
|
358
|
+
system "edit #{files.map { |f| %{'#{f}'} } * ' '}"
|
359
|
+
end
|
360
|
+
|
361
|
+
class Regexp
|
362
|
+
# Show the match of this Regexp on the +string+.
|
363
|
+
def show_match(string)
|
364
|
+
string =~ self ? "#{$`}<<#{$&}>>#{$'}" : "no match"
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
if IRB.conf[:PROMPT]
|
369
|
+
IRB.conf[:PROMPT][:CUSTOM] = {
|
370
|
+
:PROMPT_I => ">> ",
|
371
|
+
:PROMPT_N => ">> ",
|
372
|
+
:PROMPT_S => "%l> ",
|
373
|
+
:PROMPT_C => "+> ",
|
374
|
+
:RETURN => " # => %s\n"
|
375
|
+
}
|
376
|
+
IRB.conf[:PROMPT_MODE] = :CUSTOM
|
377
|
+
end
|
378
|
+
|
379
|
+
module ::IRB
|
380
|
+
class Context
|
381
|
+
def init_save_history
|
382
|
+
unless (class<<@io;self;end).include?(HistorySavingAbility)
|
383
|
+
@io.extend(HistorySavingAbility)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
def save_history
|
388
|
+
IRB.conf[:SAVE_HISTORY]
|
389
|
+
end
|
390
|
+
|
391
|
+
def save_history=(val)
|
392
|
+
IRB.conf[:SAVE_HISTORY] = val
|
393
|
+
if val
|
394
|
+
main_context = IRB.conf[:MAIN_CONTEXT]
|
395
|
+
main_context = self unless main_context
|
396
|
+
main_context.init_save_history
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
def history_file
|
401
|
+
IRB.conf[:HISTORY_FILE]
|
402
|
+
end
|
403
|
+
|
404
|
+
def history_file=(hist)
|
405
|
+
IRB.conf[:HISTORY_FILE] = hist
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
module HistorySavingAbility
|
410
|
+
include Readline
|
411
|
+
|
412
|
+
def HistorySavingAbility.create_finalizer
|
413
|
+
at_exit do
|
414
|
+
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
|
415
|
+
if hf = IRB.conf[:HISTORY_FILE]
|
416
|
+
file = File.expand_path(hf)
|
417
|
+
end
|
418
|
+
file = IRB.rc_file("_history") unless file
|
419
|
+
open(file, 'w' ) do |f|
|
420
|
+
hist = HISTORY.to_a
|
421
|
+
f.puts(hist[-num..-1] || hist)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
def HistorySavingAbility.extended(obj)
|
428
|
+
HistorySavingAbility.create_finalizer
|
429
|
+
obj.load_history
|
430
|
+
obj
|
431
|
+
end
|
432
|
+
|
433
|
+
def load_history
|
434
|
+
hist = IRB.conf[:HISTORY_FILE]
|
435
|
+
hist = IRB.rc_file("_history") unless hist
|
436
|
+
if File.exist?(hist)
|
437
|
+
open(hist) do |f|
|
438
|
+
f.each {|l| HISTORY << l.chomp}
|
439
|
+
end
|
440
|
+
end
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
IRB.conf[:SAVE_HISTORY] = 1000
|
445
|
+
|
446
|
+
# List contents of directory
|
447
|
+
def ls(*args)
|
448
|
+
puts `ls #{args.map { |x| "'#{x}'" } * ' '}`
|
449
|
+
end
|
450
|
+
|
451
|
+
if ENV['RAILS_LOG'].to_i == 1
|
452
|
+
require 'logger'
|
453
|
+
Object.const_defined?(:RAILS_DEFAULT_LOGGER) or
|
454
|
+
Object.const_set :RAILS_DEFAULT_LOGGER, Logger.new(STDOUT)
|
455
|
+
end
|