-
Notifications
You must be signed in to change notification settings - Fork 0
/
irbrc
46 lines (39 loc) · 1.02 KB
/
irbrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
['pp','irb/completion','irb/ext/save-history','rubygems'].each {|lib| require lib}
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
#IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:AUTO_INDENT] = true
require 'tempfile'
class InteractiveEditor
attr_accessor :editor
def initialize(editor = :vim)
@editor = editor.to_s
if @editor == "mate"
@editor = "mate -w"
end
end
def edit
unless @file
@file = Tempfile.new("irb_tempfile")
end
system("#{@editor} #{@file.path}")
execute
end
def execute
@file.rewind
Object.class_eval(@file.read)
rescue Exception => error
puts error
end
end
def edit(editor)
unless IRB.conf[:interactive_editors] && IRB.conf[:interactive_editors][editor]
IRB.conf[:interactive_editors] ||= {}
IRB.conf[:interactive_editors][editor] = InteractiveEditor.new(editor)
end
IRB.conf[:interactive_editors][editor].edit
end
def vi
edit(:vim)
end