irt 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +90 -14
- data/VERSION +1 -1
- data/bin/irt +4 -4
- data/irt.gemspec +11 -5
- data/irtrc +3 -0
- data/lib/irt/commands/core.rb +11 -0
- data/lib/irt/commands/edit.rb +8 -12
- data/lib/irt/commands/help.rb +19 -7
- data/lib/irt/commands/ri.rb +59 -24
- data/lib/irt/commands/test.rb +1 -1
- data/lib/irt/extensions/irb/context.rb +8 -4
- data/lib/irt/extensions/object.rb +21 -0
- data/lib/irt/utils.rb +20 -4
- data/lib/irt.rb +18 -21
- metadata +7 -16
data/README.markdown
CHANGED
@@ -19,8 +19,8 @@ that will make your life a lot easier.
|
|
19
19
|
- recording of session steps with filtering
|
20
20
|
- easy testing based on recorded steps
|
21
21
|
- easy in place opening of backtraced files
|
22
|
-
- in place editing with syntax highlight
|
23
|
-
- visual comparing tool and
|
22
|
+
- in place editing of objects and files with syntax highlight
|
23
|
+
- visual comparing tool, navigation and inspecting aids
|
24
24
|
- system and session shortcuts... and much more
|
25
25
|
|
26
26
|
### Testing made easy
|
@@ -148,7 +148,7 @@ It works also from the rails code, while the server is running. (See Rails)
|
|
148
148
|
The 'self' of the new session will be the 'self' at the line you called it, so you can play with local variables
|
149
149
|
and methods as you would do it at that line.
|
150
150
|
|
151
|
-
If you use 'nano' or 'vi' in a binding session you will open the file that contains the 'irt binding'
|
151
|
+
If you use 'nano', 'emacs' or 'vi' in a binding session you will open the file that contains the 'irt binding'
|
152
152
|
call at that line: very handy to edit your code in place.
|
153
153
|
|
154
154
|
When you close the session with 'exit' (or 'x' or 'q'), IRT will not pass back anything from the binding session.
|
@@ -191,7 +191,7 @@ or if your system supports it you can use 'copy_lines' (or 'cl') and have them r
|
|
191
191
|
You can also do the same with all the session lines using 'print_all_lines' (or 'pll')
|
192
192
|
or copy them all 'copy_all_lines' (or 'cll').
|
193
193
|
|
194
|
-
That 'pl'-copy or 'cl' plus the 'vi' or '
|
194
|
+
That 'pl'-copy or 'cl' plus the 'vi', 'nano' or 'emacs' irt command (or the 'cnn' and 'cvi' commands)
|
195
195
|
are a very time saver combination. See the [IRT Tutorial](https://github.com/ddnexus/irt/raw/master/irt-tutorial.pdf "IRT Tutorial") for details.
|
196
196
|
|
197
197
|
## Testing
|
@@ -222,7 +222,7 @@ IRT.tail_on_irt = true for automatic tail) so you have an instant feedback about
|
|
222
222
|
failure comes from. It also opens an interactive session at that point with all
|
223
223
|
the variables loaded, so you can immediately and interactively try and fix what went wrong.
|
224
224
|
|
225
|
-
If you want to edit the running file, just type 'nano' or
|
225
|
+
If you want to edit the running file, just type 'nano, 'emacs' or 'vi' without any argument and you will open
|
226
226
|
the file at the current line. Edit, save and exit from the editor, and you will continue your session
|
227
227
|
from the point you left. You can also 'rerun' the same file (or 'rr') when you need to reload the whole code.
|
228
228
|
|
@@ -240,9 +240,9 @@ a fresh loaded environment.
|
|
240
240
|
|
241
241
|
## Editing Tools
|
242
242
|
|
243
|
-
### In Place Editing
|
243
|
+
### In Place Editing of Files
|
244
244
|
|
245
|
-
You can open the current executed file at the current line by just typing 'nano' or 'vi'
|
245
|
+
You can open the current executed file at the current line by just typing 'nano, 'emacs' or 'vi'
|
246
246
|
and the editor with that name will be opened (in insert mode). Paste and/or edit and save what
|
247
247
|
you want and 'rerun' (or 'rr') the file to try/test the changes.
|
248
248
|
|
@@ -253,16 +253,24 @@ If you don't like the default editor, you have just to set the IRT.edit_command_
|
|
253
253
|
You will also find the info about how to automatically have your files syntax highlighted when opened in vi
|
254
254
|
or nano. See "Goodies" below.
|
255
255
|
|
256
|
+
### In Place Editing of Object
|
257
|
+
|
258
|
+
With just calling your preferred CLI editor on any object, you can edit the yaml-dumped object and have it
|
259
|
+
returned in your console:
|
260
|
+
|
261
|
+
>> {:a => 2}.vi # opens the yaml-dump with vi
|
262
|
+
#=> {:an_edited => 'value'}
|
263
|
+
|
256
264
|
### Copy-Open
|
257
265
|
|
258
266
|
You can combine the copy to clipboard feature, with the in place edit feature by using one of the
|
259
|
-
commands 'cnano', 'cvi' or 'cedit', so saving a lot of boring steps. It use the copy_to_clipboard
|
267
|
+
commands 'cnano', 'cemacs' 'cvi' or 'cedit', so saving a lot of boring steps. It use the copy_to_clipboard
|
260
268
|
command from your system. see below.
|
261
269
|
|
262
270
|
### Copy to Clipboard Command
|
263
271
|
|
264
272
|
IRT provides a few commands that will use an external command of your system to copy the
|
265
|
-
last lines to the clipboard: 'copy_lines' (or 'cl'), 'cnano', 'cvi', 'cedit' use that command
|
273
|
+
last lines to the clipboard: 'copy_lines' (or 'cl'), 'cnano', 'cemacs', 'cvi', 'cedit' use that command
|
266
274
|
avoiding you the boring task to select the output from the terminal and copy it.
|
267
275
|
|
268
276
|
It uses 'pbcopy' on MacOS (which should be already installed on any mac),
|
@@ -276,7 +284,7 @@ the stdin to the clipboard.
|
|
276
284
|
|
277
285
|
I have never been a big fan of CLI editors like vi or nano, but I really appreciate them
|
278
286
|
when combined with IRT. Having the file I need to edit, opened at the right line at the touch of a 2 letter
|
279
|
-
command ('nn' or '
|
287
|
+
command ('nn', 'vi' or 'em') is really fast and powerful.
|
280
288
|
|
281
289
|
You have just to know a few very basic commands
|
282
290
|
like paste, save, quit, and eventually a couple of other, and you will save a lot of time and steps.
|
@@ -311,6 +319,41 @@ For those (like me) that are not used to CLI editors here's a quick reference fo
|
|
311
319
|
paste (line) [Esc (return to command mode)]
|
312
320
|
type 'p'
|
313
321
|
|
322
|
+
EMACS
|
323
|
+
paste from clipboard with your usual OS command
|
324
|
+
quit Ctrl-X Ctrl-C
|
325
|
+
type 'y'<enter> confirming that you want also to save
|
326
|
+
type 'n' confirming that you don't want to save
|
327
|
+
Editing
|
328
|
+
copy (line) Ctrl-A Ctrl-SPACE Ctrl-N Alt-w
|
329
|
+
cut (line) Ctrl-K
|
330
|
+
uncut (paste) Ctrl-Y
|
331
|
+
|
332
|
+
|
333
|
+
### Note about IDEs
|
334
|
+
|
335
|
+
If you prefer to inspect/edit your files with your preferred IDE, you should add a line to
|
336
|
+
the ~/.irtrc file (create it if you don't have one) indicating the command format for your IDE,
|
337
|
+
in order to open a file at a certain line.
|
338
|
+
|
339
|
+
These are exaples of a few setups for different IDEs:
|
340
|
+
|
341
|
+
# Plain Eclipse on Mac X (opens the file but misses the line number)
|
342
|
+
IRT.edit_command_format = %(open -a "/Applications/eclipse/Eclipse.app" %1$s)
|
343
|
+
|
344
|
+
# Eclipse with installed EclipseCall plugin (platform independent, file and line number ok)
|
345
|
+
# Eclipse should be running
|
346
|
+
# http://www.jaylib.org/pmwiki/pmwiki.php/EclipsePlugins/EclipseCall
|
347
|
+
# update site: http://www.jaylib.org/eclipsecall
|
348
|
+
IRT.edit_command_format = %(java -jar eclipsecall.jar %1$s -G%2$s)
|
349
|
+
|
350
|
+
# NetBeans
|
351
|
+
IRT.edit_command_format = %(netbeans --open %1$s:%2$s)
|
352
|
+
|
353
|
+
You will use the 'edit' (or 'ed') command to inspect/edit your file with the IDE you setup.
|
354
|
+
If you create a format for any IDE not listed in the example, please, send it to me, so I will
|
355
|
+
add it to the list for other users. Thank you.
|
356
|
+
|
314
357
|
## Inspecting Tools
|
315
358
|
|
316
359
|
### Call irt from your code
|
@@ -362,7 +405,7 @@ are also enhanced a bit: when invoked with no arguments, they use the last value
|
|
362
405
|
When an error occurs, IRT shows you an indexed exception backtrace: each file:line in the backtrace
|
363
406
|
has an index number (in brackets) that you can use to open that file at that line with your preferred in-place editor.
|
364
407
|
|
365
|
-
You have just to type '<editor> <index>' (<editor> is one of 'vi', 'nano' (or 'nn') 'edit' (or 'ed'),
|
408
|
+
You have just to type '<editor> <index>' (<editor> is one of 'vi', 'nano' (or 'nn'), 'emacs' (or 'em'), 'edit' (or 'ed'),
|
366
409
|
and <index> is the index number shown in the backtrace), and you will open it in insert mode. Example:
|
367
410
|
|
368
411
|
# backtraced line: from /Users/dd/dev/hobo3/hobo/lib/hobo/controller/model.rb:57:in `each' [3]
|
@@ -382,8 +425,9 @@ the wanted line. Example:
|
|
382
425
|
|
383
426
|
### Contextual ri doc with autocompletion
|
384
427
|
|
385
|
-
IRT offers the 'ri' command
|
386
|
-
|
428
|
+
IRT offers the 'ri' command implemented with fastri for RUBY_VERSION < 1.9.2, or 'bri' for RUBY_VERSION >= 1.9.2:
|
429
|
+
you must install the right gem for your ruby version in order to make it work.
|
430
|
+
See also the IRT.ri_command_format option if you want to customize it.
|
387
431
|
|
388
432
|
In its basic form the 'ri' command can accept a string as the system ri command does (you can even omit the quotes).
|
389
433
|
|
@@ -427,6 +471,12 @@ Example:
|
|
427
471
|
Returns true if array and other are the same object, or are both
|
428
472
|
arrays with the same content.
|
429
473
|
|
474
|
+
If you want to search a literal string (i.e. not interpreted) you must use single or double quotes
|
475
|
+
and the string will be passed verbatim to the system ri command.
|
476
|
+
|
477
|
+
If you have a long documentation coming from the ri search, or even if you want just to keep your screen clean,
|
478
|
+
you can use the 'pri' (i.e. paged ri). It works exactly like 'ri', but uses the pager to show any result from the ri search.
|
479
|
+
|
430
480
|
### IRT Help
|
431
481
|
|
432
482
|
The IRT Commands are the methods that you can call from any IRT console session, while the Directives are
|
@@ -449,6 +499,18 @@ You can use the 'sh' as an alias of 'system' with the difference that you don't
|
|
449
499
|
>> sh git rebase -i HEAD~5
|
450
500
|
>> sh cat #{file_path}
|
451
501
|
|
502
|
+
### Pager
|
503
|
+
|
504
|
+
When you have any long string to inspect, or some code printing a lot of text to stdout
|
505
|
+
you can use the 'pager' (or 'pg') command, and the output will be managed by the pager
|
506
|
+
('less' by default, but you can change it with the pager\_format\_command option).
|
507
|
+
|
508
|
+
# with a string
|
509
|
+
pg some_long_string
|
510
|
+
|
511
|
+
# with a block of code printing to stdout
|
512
|
+
pg { irt_help }
|
513
|
+
|
452
514
|
### FileUtils
|
453
515
|
|
454
516
|
All the FileUtils methods are included as commands: just call them in the session
|
@@ -530,6 +592,9 @@ which should work quite well without any change:
|
|
530
592
|
# the format to build the command to launch vi
|
531
593
|
# IRT.vi_command_format = %(vi "%1$s" +%2$d)
|
532
594
|
|
595
|
+
# the format to build the command to lauch emacs
|
596
|
+
# IRT.emacs_command_format = %(emacs +%2$d "%1$s")
|
597
|
+
|
533
598
|
# the format to build the command to launch the ri tool
|
534
599
|
# if RUBY_VERSION < 1.9.2 uses qri (from fastri) else bri
|
535
600
|
# IRT.ri_command_format = %(qri -f #{Dye.color? ? 'ansi' : 'plain'} "%s")
|
@@ -672,12 +737,23 @@ You must add the gem to your Gemfile, to make the bundler happy:
|
|
672
737
|
eventually adding it only to the group that you prefer. Anyway, if the irt executable detects that you don't have it set,
|
673
738
|
it will ask and eventually add it for you.
|
674
739
|
|
675
|
-
## Known
|
740
|
+
## Known Issues
|
741
|
+
|
742
|
+
### Yaml serialization
|
676
743
|
|
677
744
|
IRT uses yaml serialization, and inherits its limits (e.g.: Yaml cannot dump anonymous classes, MatchData, object that contains binding, etc.)
|
678
745
|
so if you stumble upon on one of them, you have just to test the subparts of the object that you cannot dump. For example, instead of testing one whole anonymous
|
679
746
|
class, (which is however a bad idea) you can add tests for the values returned by its methods or variables.
|
680
747
|
|
748
|
+
### Irb jobs
|
749
|
+
|
750
|
+
IRT disables the traditionals irb jobs. You can still open any session like you do with the standard irb,
|
751
|
+
but the new session is not created as a new thread, therefore the 'jobs' related commands are useless.
|
752
|
+
In practice the only real limitation is that you have to exit from an inspecting or binding session
|
753
|
+
in order to switch back to an interactive session, while threaded sessions would allow you to switch and kill the thread
|
754
|
+
indipendently. This will probably be addressed in a next version of irt.
|
755
|
+
Please, send me a line if this issue is bugging you, so I will try to fix it faster.
|
756
|
+
|
681
757
|
## Copyright
|
682
758
|
|
683
759
|
Copyright (c) 2010-2011 Domizio Demichelis. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.2
|
data/bin/irt
CHANGED
@@ -7,7 +7,7 @@ require 'fileutils'
|
|
7
7
|
require 'optparse'
|
8
8
|
require 'irt/utils'
|
9
9
|
|
10
|
-
copy = IRT
|
10
|
+
copy = IRT.copyright
|
11
11
|
|
12
12
|
options = {}
|
13
13
|
|
@@ -45,7 +45,7 @@ EOB
|
|
45
45
|
end
|
46
46
|
|
47
47
|
opts.on( '-v', '--version', 'Shows the version and exits' ) do
|
48
|
-
puts IRT
|
48
|
+
puts IRT.version
|
49
49
|
exit
|
50
50
|
end
|
51
51
|
|
@@ -63,7 +63,7 @@ puts copy
|
|
63
63
|
|
64
64
|
paths = if ARGV.empty?
|
65
65
|
options[:interactive_eof] = true
|
66
|
-
[ IRT
|
66
|
+
[ IRT.create_tmp_file ]
|
67
67
|
else
|
68
68
|
ARGV.map {|p| File.expand_path(p) }
|
69
69
|
end
|
@@ -92,7 +92,7 @@ cmd_format = if File.exists?('./config/environment.rb') && !options[:no_rails]
|
|
92
92
|
IRT::Prompter.say_warning %(The Gemfile doesn't look to include any 'gem "irt"' statement.\nIRT will probably not work until you add it!)
|
93
93
|
IRT::Prompter.yes?("Do you want to add irt to your Gemfile?", :hint => '[enter=y|n]', :default => 'y') do
|
94
94
|
File.open('Gemfile', 'a') do |f|
|
95
|
-
f.puts %(
|
95
|
+
f.puts %(\ngem "irt")
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
data/irt.gemspec
CHANGED
@@ -14,15 +14,21 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.add_runtime_dependency('differ', [">= 0.1.1"])
|
15
15
|
s.add_runtime_dependency('dye', [">= 0.1.3"])
|
16
16
|
s.add_runtime_dependency('prompter', [">= 0.1.4"])
|
17
|
-
|
18
|
-
s.add_runtime_dependency('bri', [">= 0.1.5"])
|
19
|
-
else
|
20
|
-
s.add_runtime_dependency('fastri', [">= 0.3.1.1"])
|
21
|
-
end
|
17
|
+
s.requirements << "In order to use the IRT contextual ri command you must install the gem 'bri' (ruby >=1.9.2) or 'fastri' (ruby < 1.9.2)"
|
22
18
|
|
23
19
|
s.executables = ['irt', 'irt_irb', 'irt_rails2']
|
24
20
|
s.files = `git ls-files -z`.split("\0") - %w[irt-tutorial.pdf]
|
21
|
+
s.post_install_message = <<EOM
|
25
22
|
|
23
|
+
********************************************************************************
|
24
|
+
|
25
|
+
In order to use the IRT contextual ri command you must also install the gem:
|
26
|
+
"bri" if you run ruby >= 1.9.2
|
27
|
+
"fastri" if you run ruby < 1.9.2
|
28
|
+
|
29
|
+
********************************************************************************
|
30
|
+
|
31
|
+
EOM
|
26
32
|
s.name = name
|
27
33
|
s.version = version
|
28
34
|
s.date = Date.today.to_s
|
data/irtrc
CHANGED
@@ -32,6 +32,9 @@
|
|
32
32
|
# the format to build the command to launch vi
|
33
33
|
# IRT.vi_command_format = %(vi "%1$s" +%2$d)
|
34
34
|
|
35
|
+
# the format to build the command to lauch emacs
|
36
|
+
# IRT.emacs_command_format = %(emacs +%2$d "%1$s")
|
37
|
+
|
35
38
|
# the format to build the command to launch the ri tool
|
36
39
|
# if RUBY_VERSION < 1.9.2 uses qri (from fastri) else bri
|
37
40
|
# IRT.ri_command_format = %(qri -f #{Dye.color? ? 'ansi' : 'plain'} "%s")
|
data/lib/irt/commands/core.rb
CHANGED
@@ -57,6 +57,17 @@ module IRT
|
|
57
57
|
system *args
|
58
58
|
end
|
59
59
|
|
60
|
+
def pager(arg=nil, &block)
|
61
|
+
ensure_session
|
62
|
+
raise ArgumentError, "You must pass an arguent or a block" if arg.nil? && block.nil?
|
63
|
+
# in case of a block we will just capture in memory its whole output to stdout
|
64
|
+
output = arg || capture(&block)
|
65
|
+
IO.popen(IRT.pager_command, 'w') do |io|
|
66
|
+
io.puts output
|
67
|
+
end
|
68
|
+
end
|
69
|
+
alias_method :pg, :pager
|
70
|
+
|
60
71
|
end
|
61
72
|
end
|
62
73
|
end
|
data/lib/irt/commands/edit.rb
CHANGED
@@ -14,30 +14,26 @@ module IRT
|
|
14
14
|
end
|
15
15
|
alias_method :cll, :copy_all_lines
|
16
16
|
|
17
|
-
|
17
|
+
IRT::EDITORS.each_pair do |name, short|
|
18
18
|
|
19
|
-
define_method(
|
19
|
+
define_method(name) do |*args|
|
20
20
|
ensure_session
|
21
|
-
run_editor(
|
21
|
+
run_editor(name, *args)
|
22
22
|
end
|
23
23
|
|
24
|
-
define_method(:"c#{
|
24
|
+
define_method(:"c#{name}") do |*args|
|
25
25
|
ensure_session
|
26
26
|
copy_lines
|
27
|
-
send
|
27
|
+
send name, *args
|
28
28
|
end
|
29
29
|
|
30
|
+
alias_method short, name if short
|
31
|
+
alias_method :"c#{short}", :"c#{name}" if short
|
30
32
|
end
|
31
|
-
alias_method :nn, :nano
|
32
|
-
alias_method :ed, :edit
|
33
|
-
alias_method :cnn, :cnano
|
34
|
-
alias_method :ced, :cedit
|
35
33
|
|
36
34
|
private
|
37
35
|
|
38
36
|
def run_editor(cmd, *args)
|
39
|
-
cmd_format = IRT.send("#{cmd}_command_format".to_sym)
|
40
|
-
raise IRT::NotImplementedError, "#{cmd}_command_format missing" unless cmd_format
|
41
37
|
arg = args.first if args.size == 1
|
42
38
|
file, line = case
|
43
39
|
when args.empty?
|
@@ -66,7 +62,7 @@ module IRT
|
|
66
62
|
else
|
67
63
|
args
|
68
64
|
end
|
69
|
-
|
65
|
+
IRT.edit_with(cmd, file, line)
|
70
66
|
end
|
71
67
|
|
72
68
|
def copy_to_clipboard(cmd)
|
data/lib/irt/commands/help.rb
CHANGED
@@ -24,7 +24,7 @@ module IRT
|
|
24
24
|
print_all_lines|pll Like print_line but prints all the sessions lines
|
25
25
|
|
26
26
|
#{label " In Place Editing Commands ", :interactive_color}
|
27
|
-
(<editor> can be 'vi', 'nano|nn', 'edit|ed')
|
27
|
+
(<editor> can be 'vi', 'nano|nn', 'emacs|em', 'edit|ed')
|
28
28
|
<editor> Uses <editor> to open the current evalued file at
|
29
29
|
the current evalued line for in place edit
|
30
30
|
<editor> file[, line] Uses <editor> to open file [at line] for in place
|
@@ -38,11 +38,9 @@ module IRT
|
|
38
38
|
the backtraced line
|
39
39
|
|
40
40
|
#{label( " Copy-Edit Commands ", :interactive_color ) + IRT.dye(" (use copy_to_clipboard_command)", :interactive_color, :bold)}
|
41
|
-
copy_lines|cl
|
42
|
-
copy_all_lines|cll
|
43
|
-
|
44
|
-
cvi Like vi, but copy the last session lines first
|
45
|
-
cedit|ced Like edit, but copy the last session lines first
|
41
|
+
copy_lines|cl Copies the last session lines to the clipboard
|
42
|
+
copy_all_lines|cll Copies all the sessions' lines to the clipboard
|
43
|
+
c<editor> Like `copy_lines` and <editor> in just one step
|
46
44
|
|
47
45
|
#{label(" Test Commands ", :interactive_color) + IRT.dye(" (only available in interactive sessions)", :interactive_color, :bold)}
|
48
46
|
add_desc|dd desc Adds a description for the test in the log
|
@@ -57,13 +55,20 @@ module IRT
|
|
57
55
|
(e.g. pwd, touch, mkdir, mv, cp, rm, rm_rf, compare_files, ...)
|
58
56
|
|
59
57
|
#{label " Documentation Commands ", :interactive_color}
|
60
|
-
ri
|
58
|
+
ri "string_to_search" Search the ri doc for the literal string_to_search
|
59
|
+
ri to_search Search the ri doc for to_search (without quote)
|
60
|
+
If to_search represents any object in your code
|
61
|
+
it looks for the obj.class documentation
|
62
|
+
e.g.: ri arr #=> (where arr=[]) ri doc for Array
|
63
|
+
ri "" #=> ri doc for String
|
61
64
|
ri obj.any_method Search the method.owner ri doc for of any_method
|
62
65
|
(no quotes needed, and completion available)
|
63
66
|
e.g.: ri "".eql? #=> ri doc for String#eql?
|
64
67
|
ri [].eql? #=> ri doc for Array#eql?
|
65
68
|
ri n Search the ri doc for the method n in a multiple
|
66
69
|
choices list
|
70
|
+
pri ... Like the above commands for `ri ...` but uses the
|
71
|
+
pager to show the result
|
67
72
|
|
68
73
|
#{label(" Rails Commands ", :interactive_color) + IRT.dye(" (only available for Rails Apps)", :interactive_color, :bold)}
|
69
74
|
rails_log_on Turn the rails log-in-console ON
|
@@ -82,6 +87,8 @@ module IRT
|
|
82
87
|
rerun the current file
|
83
88
|
irt_help|hh Shows this screen
|
84
89
|
sh command Alias for system("command") (no quotes needed)
|
90
|
+
pager|pg string|block Uses the pager to show a long string or executes
|
91
|
+
block and shows its captured stdout
|
85
92
|
|
86
93
|
#{label " Session Directives ", :file_color}
|
87
94
|
irt Opens an interactive session which retains the
|
@@ -104,6 +111,11 @@ module IRT
|
|
104
111
|
captured stdout
|
105
112
|
Object#own_methods Returns the methods implemented by the receiver
|
106
113
|
itself (not inherited)
|
114
|
+
Object#<editor> (<editor> can be 'vi', 'nano|nn', 'emacs|em')
|
115
|
+
Yaml-dump the object in a tmp.yml file and opens it
|
116
|
+
with <editor>. After your editing and save returns
|
117
|
+
the evaluated yaml file
|
118
|
+
e.g.: {:a => 2}.vi #=> {:an_edited => 'value'}
|
107
119
|
Method#location When possible, it returns file and line where the
|
108
120
|
method is defined. It is uitable to be passed to the
|
109
121
|
in place editing commands.
|
data/lib/irt/commands/ri.rb
CHANGED
@@ -8,50 +8,85 @@ module IRT
|
|
8
8
|
@@choices_map = {}
|
9
9
|
end
|
10
10
|
|
11
|
-
def ri(arg)
|
11
|
+
def ri(arg, literal=false)
|
12
12
|
ensure_session
|
13
13
|
raise IRT::NotImplementedError, "No available ri_command_format for this system." unless IRT.ri_command_format
|
14
14
|
case
|
15
|
-
|
16
|
-
return puts('nil')
|
15
|
+
|
17
16
|
when arg.match(/^\d+$/)
|
18
17
|
if @@choices_map.key?(arg)
|
19
18
|
to_search = @@choices_map[arg]
|
20
19
|
else
|
21
20
|
raise IndexError, "No such method index -- [#{arg}]"
|
22
21
|
end
|
22
|
+
|
23
|
+
when literal
|
24
|
+
if output = process_ri(arg)
|
25
|
+
puts(output)
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
when arg !~ /\./
|
30
|
+
begin
|
31
|
+
obj = eval arg, IRB.CurrentContext.workspace.binding
|
32
|
+
to_search = obj.class
|
33
|
+
rescue NameError
|
34
|
+
if output = process_ri(arg)
|
35
|
+
puts(output)
|
36
|
+
return
|
37
|
+
end
|
38
|
+
raise
|
39
|
+
end
|
40
|
+
|
23
41
|
else
|
24
42
|
segm = arg.split('.')
|
25
43
|
to_search = segm.pop
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
44
|
+
receiver = eval segm.join('.'), IRB.CurrentContext.workspace.binding
|
45
|
+
raise NoMethodError, %(undefined method '#{to_search}' for #{receiver.inspect}:#{receiver.class}) \
|
46
|
+
unless receiver.respond_to? to_search.to_sym
|
47
|
+
meth = receiver.method(to_search.to_sym).inspect
|
48
|
+
meth = meth.match(/^\#<Method: (.+)>$/)[1]
|
49
|
+
if m = meth.match(/\((.+)\)(.+)/)
|
50
|
+
to_search = m[1] + m[2]
|
51
|
+
else
|
52
|
+
to_search = meth
|
33
53
|
end
|
34
54
|
end
|
35
|
-
|
55
|
+
|
56
|
+
puts process_ri(to_search) || 'Nothing found!'
|
57
|
+
end
|
58
|
+
|
59
|
+
def pri(arg)
|
60
|
+
pager { ri arg }
|
36
61
|
end
|
37
62
|
|
38
63
|
private
|
39
64
|
|
40
65
|
def process_ri(to_search)
|
41
66
|
ri = `#{sprintf(IRT.ri_command_format, to_search)}`
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
67
|
+
ri_problem unless $?.to_i == 0
|
68
|
+
return if ri.match(/^(nil|No matching results found)$/)
|
69
|
+
if m = ri.match(/^(-+.*Multiple choices:.*\n\n)(.+)/m)
|
70
|
+
output, methods = m.captures
|
71
|
+
IRT::Commands::Ri.reset_choices_map
|
72
|
+
fmt = "%+7s %s\n"
|
73
|
+
methods.gsub(/\s+/, '').split(',').each_with_index do |m, i|
|
74
|
+
@@choices_map[(i+1).to_s] = m
|
75
|
+
output << sprintf( fmt, "#{i+1}", m )
|
76
|
+
end
|
77
|
+
output << "\n"
|
78
|
+
else
|
79
|
+
output = ri
|
80
|
+
end
|
81
|
+
output
|
82
|
+
end
|
83
|
+
|
84
|
+
def ri_problem
|
85
|
+
ri_gem = IRT::RubyVersion >= '1.9.2' ? 'bri' : 'fastri'
|
86
|
+
message = system("#{required} -v") ?
|
87
|
+
"Bad ri_command_format for this system." :
|
88
|
+
%(You must install the "#{ri_gem}" gem to use this command with ruby #{RUBY_VERSION}.)
|
89
|
+
raise IRT::NotImplementedError, message
|
55
90
|
end
|
56
91
|
|
57
92
|
end
|
data/lib/irt/commands/test.rb
CHANGED
@@ -41,12 +41,16 @@ module IRB
|
|
41
41
|
# skip setting last_value for non_setting_commands
|
42
42
|
if line =~ /^\s*(#{quoted_option_string(IRT.log.non_setting_commands)})\b(.*)$/
|
43
43
|
command, args = $1, $2
|
44
|
-
if command =~ /^(sh|ri)$/ && irt_mode != :file
|
44
|
+
if command =~ /^(sh|ri|pri)$/ && irt_mode != :file
|
45
45
|
args = args.strip if args
|
46
|
-
|
47
|
-
|
46
|
+
line = if args.match(/^('|").+\1$/)
|
47
|
+
command == 'sh' ? "#{command} #{args}" : "#{command} #{args}, true"
|
48
|
+
else
|
49
|
+
args = "%(#{args})" unless args.empty?
|
50
|
+
"#{command} #{args}"
|
51
|
+
end
|
48
52
|
end
|
49
|
-
IRT::Commands::Ri.reset_choices_map unless command
|
53
|
+
IRT::Commands::Ri.reset_choices_map unless command =~ /^(ri|pri)$/
|
50
54
|
self.echo = false
|
51
55
|
res = @workspace.evaluate(self, line, irb_path, line_no)
|
52
56
|
if command =~ /^(#{IRT.log.ignored_echo_commands * '|'})$/
|
@@ -1,7 +1,28 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
1
3
|
class Object
|
2
4
|
|
3
5
|
def own_methods
|
4
6
|
methods - self.class.methods
|
5
7
|
end
|
6
8
|
|
9
|
+
IRT::EDITORS.each_pair do |name, short|
|
10
|
+
# with IDEs we cannot come back after editing
|
11
|
+
next if name == :edit
|
12
|
+
|
13
|
+
define_method(name) do
|
14
|
+
t = Tempfile.new(['', '.yml'])
|
15
|
+
t << to_yaml
|
16
|
+
t.flush
|
17
|
+
IRT.edit_with(name, t.path)
|
18
|
+
return self unless File.exists?( t.path )
|
19
|
+
obj = YAML::load_file t.path
|
20
|
+
t.close
|
21
|
+
obj
|
22
|
+
end
|
23
|
+
|
24
|
+
alias_method short, name if short
|
25
|
+
|
26
|
+
end
|
27
|
+
|
7
28
|
end
|
data/lib/irt/utils.rb
CHANGED
@@ -2,17 +2,23 @@ require 'irt/prompter'
|
|
2
2
|
|
3
3
|
module IRT
|
4
4
|
|
5
|
-
extend self
|
6
|
-
|
7
5
|
def cli?
|
8
6
|
!!ENV['IRT_COMMAND']
|
9
7
|
end
|
10
8
|
|
9
|
+
def lib_path
|
10
|
+
File.expand_path '../../../lib', __FILE__
|
11
|
+
end
|
12
|
+
|
13
|
+
# this fixes a little imperfection of the YAML::dump method
|
14
|
+
# which adds a space at the end of the class
|
15
|
+
def yaml_dump(val)
|
16
|
+
yml = "\n" + YAML.dump(val)
|
17
|
+
yml.gsub(/ +\n/, "\n")
|
18
|
+
end
|
11
19
|
|
12
20
|
module Utils
|
13
21
|
|
14
|
-
extend self
|
15
|
-
|
16
22
|
def create_tmp_file()
|
17
23
|
require 'tempfile'
|
18
24
|
tmp_file = Tempfile.new(['', '.irt'])
|
@@ -35,6 +41,12 @@ module IRT
|
|
35
41
|
ask_run_new_file new_file_path, source_path, tmp
|
36
42
|
end
|
37
43
|
|
44
|
+
def edit_with(editor, file, line=nil)
|
45
|
+
cmd_format = IRT.send("#{editor}_command_format".to_sym)
|
46
|
+
raise IRT::NotImplementedError, "#{cmd}_command_format missing" unless cmd_format
|
47
|
+
system sprintf(cmd_format, file, line||0)
|
48
|
+
end
|
49
|
+
|
38
50
|
def version
|
39
51
|
@version ||= File.read(File.expand_path('../../../VERSION', __FILE__)).strip
|
40
52
|
end
|
@@ -73,4 +85,8 @@ module IRT
|
|
73
85
|
end
|
74
86
|
|
75
87
|
end
|
88
|
+
|
89
|
+
extend self
|
90
|
+
extend Utils
|
91
|
+
|
76
92
|
end
|
data/lib/irt.rb
CHANGED
@@ -9,11 +9,6 @@ require 'pp'
|
|
9
9
|
require 'yaml'
|
10
10
|
require 'rbconfig'
|
11
11
|
require 'pathname'
|
12
|
-
require 'irt/extensions/kernel'
|
13
|
-
require 'irt/extensions/object'
|
14
|
-
require 'irt/extensions/method'
|
15
|
-
require 'irt/extensions/irb'
|
16
|
-
require 'irb/completion'
|
17
12
|
require 'dye'
|
18
13
|
require 'irt/log'
|
19
14
|
require 'irt/hunks'
|
@@ -25,8 +20,6 @@ require 'irt/utils'
|
|
25
20
|
|
26
21
|
module IRT
|
27
22
|
|
28
|
-
VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip
|
29
|
-
|
30
23
|
OS = case RbConfig::CONFIG['host_os']
|
31
24
|
when /mswin|msys|mingw32|windows/i
|
32
25
|
:windows
|
@@ -40,6 +33,13 @@ module IRT
|
|
40
33
|
:unknown
|
41
34
|
end
|
42
35
|
|
36
|
+
EDITORS = { :vi => nil,
|
37
|
+
:nano => :nn,
|
38
|
+
:emacs => :em,
|
39
|
+
:edit => :ed }
|
40
|
+
|
41
|
+
EDITORS.keys.each {|k| attr_accessor :"#{k}_command_format" }
|
42
|
+
|
43
43
|
class IndexError < RuntimeError ; end
|
44
44
|
class SessionModeError < RuntimeError ; end
|
45
45
|
class ArgumentTypeError < RuntimeError ; end
|
@@ -50,7 +50,8 @@ module IRT
|
|
50
50
|
attr_accessor :irt_on_diffs, :tail_on_irt, :fix_readline_prompt, :debug,
|
51
51
|
:rails_log, :dye_rails_log, :rails_server, :rails_server_sigint_trap,
|
52
52
|
:full_exit, :session_no, :autoload_helper_files, :dye_styles,
|
53
|
-
:copy_to_clipboard_command, :
|
53
|
+
:copy_to_clipboard_command, :pager_command, :ri_command_format
|
54
|
+
|
54
55
|
attr_reader :log, :irt_file, :initialized
|
55
56
|
|
56
57
|
def force_color=(bool)
|
@@ -98,7 +99,9 @@ module IRT
|
|
98
99
|
end
|
99
100
|
@vi_command_format = %(vi "%1$s" +%2$d)
|
100
101
|
@nano_command_format = %(nano +%2$d "%1$s")
|
102
|
+
@emacs_command_format = %(emacs +%2$d "%1$s")
|
101
103
|
@ri_command_format = IRT::RubyVersion >= '1.9.2' ? %(bri "%s") : %(qri -f #{Dye.color? ? 'ansi' : 'plain'} "%s")
|
104
|
+
@pager_command = 'less -R'
|
102
105
|
@debug = false
|
103
106
|
end
|
104
107
|
|
@@ -128,30 +131,24 @@ module IRT
|
|
128
131
|
@log.print_running_file
|
129
132
|
end
|
130
133
|
|
131
|
-
def lib_path
|
132
|
-
File.expand_path '../../lib', __FILE__
|
133
|
-
end
|
134
|
-
|
135
|
-
# this fixes a little imperfection of the YAML::dump method
|
136
|
-
# which adds a space at the end of the class
|
137
|
-
def yaml_dump(val)
|
138
|
-
yml = "\n" + YAML.dump(val)
|
139
|
-
yml.gsub(/ +\n/, "\n")
|
140
|
-
end
|
141
|
-
|
142
134
|
# this will create a tmp file and start IRB
|
143
135
|
# but it will be left in file mode at EOF (sort of irt-standby)
|
144
136
|
def start
|
145
137
|
return if initialized
|
146
|
-
puts
|
138
|
+
puts copyright
|
147
139
|
ARGV.clear
|
148
|
-
ARGV.push
|
140
|
+
ARGV.push create_tmp_file
|
149
141
|
IRB.start
|
150
142
|
end
|
151
143
|
|
152
144
|
end
|
153
145
|
|
146
|
+
require 'irt/extensions/irb'
|
147
|
+
require 'irb/completion'
|
154
148
|
IRT.init_config
|
149
|
+
require 'irt/extensions/kernel'
|
150
|
+
require 'irt/extensions/object'
|
151
|
+
require 'irt/extensions/method'
|
155
152
|
require 'irt/prompter'
|
156
153
|
require 'irt/extensions/rails' if defined?(ActiveSupport::BufferedLogger)
|
157
154
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: irt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.2.
|
5
|
+
version: 1.2.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Domizio Demichelis
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-14 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -46,17 +46,6 @@ dependencies:
|
|
46
46
|
version: 0.1.4
|
47
47
|
type: :runtime
|
48
48
|
version_requirements: *id003
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: bri
|
51
|
-
prerelease: false
|
52
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
|
-
requirements:
|
55
|
-
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version: 0.1.5
|
58
|
-
type: :runtime
|
59
|
-
version_requirements: *id004
|
60
49
|
description: If you use IRT in place of irb or Rails Console, you will have more tools that will make your life a lot easier.
|
61
50
|
email: dd.nexus@gmail.com
|
62
51
|
executables:
|
@@ -110,7 +99,9 @@ has_rdoc: true
|
|
110
99
|
homepage: http://github.com/ddnexus/irt
|
111
100
|
licenses: []
|
112
101
|
|
113
|
-
post_install_message:
|
102
|
+
post_install_message: "\n\
|
103
|
+
********************************************************************************\n\n In order to use the IRT contextual ri command you must also install the gem:\n \"bri\" if you run ruby >= 1.9.2\n \"fastri\" if you run ruby < 1.9.2\n\n\
|
104
|
+
********************************************************************************\n\n"
|
114
105
|
rdoc_options:
|
115
106
|
- --charset=UTF-8
|
116
107
|
require_paths:
|
@@ -127,8 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
118
|
- - ">="
|
128
119
|
- !ruby/object:Gem::Version
|
129
120
|
version: 1.3.6
|
130
|
-
requirements:
|
131
|
-
|
121
|
+
requirements:
|
122
|
+
- In order to use the IRT contextual ri command you must install the gem 'bri' (ruby >=1.9.2) or 'fastri' (ruby < 1.9.2)
|
132
123
|
rubyforge_project:
|
133
124
|
rubygems_version: 1.5.0
|
134
125
|
signing_key:
|