-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirbrc
171 lines (131 loc) · 4 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/ruby
# this won't bite your Bundle-using programs too
require 'rubygems'
# don't know if they are needed
#require 'irb/completion'
#require 'irb/ext/save-history'
#IRB.conf[:SAVE_HISTORY] = 100
#IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:AUTO_INDENT] = true
def provided_by lib
begin
require lib
yield
rescue LoadError
puts "#{lib} is not available"
end
end
provided_by 'wirble' do
Wirble.init
# thoose do not work, actually
MY_COLORS = {
:comma => :red,
:refers => :red,
:open_hash => :blue,
:close_hash => :blue,
:open_array => :green,
:close_array => :green,
:open_object => :light_red,
:object_class => :light_green,
:object_addr => :purple,
:object_line => :light_purple,
:close_object => :light_red,
:symbol => :yellow,
:symbol_prefix => :yellow,
:number => :cyan,
:string => :cyan,
:keyword => :white,
:range => :light_blue,
}
Wirble.colorize MY_COLORS
end
provided_by 'hirb' do
Hirb.enable :formatter => false
end
provided_by 'yaml' do
# I love that 'y something' shortcut
end
provided_by 'looksee/shortcuts' do
end
#provided_by 'soma' do
# Soma.start
#end
provided_by 'ap' do
# awesome print!
end
provided_by 'interactive_editor' do
# vi command
end
# Just for Rails...
if defined? Rails
if defined? ActiveRecord::Base
require 'logger'
ActiveRecord::Base.logger = Logger.new(STDOUT)
end
if defined? DataObjects::Sqlite3
# DataMapper::Logger.new(STDOUT, :debug)
DataObjects::Sqlite3.logger = Logger.new(STDOUT)
end
rails_root = File.basename(Rails.root || Dir.pwd)
if rails_root == 'trunk'
rails_root = File.basename(File.expand_path('..'))
end
IRB.conf[:PROMPT] ||= {}
IRB.conf[:PROMPT][:RAILS] = {
:PROMPT_I => "#{rails_root}> ",
:PROMPT_S => "#{rails_root}* ",
:PROMPT_C => "#{rails_root}? ",
:RETURN => "=> %s\n"
}
IRB.conf[:PROMPT_MODE] = :RAILS
# Called after the irb session is initialized and Rails has
# been loaded (props: Mike Clark).
#IRB.conf[:IRB_RC] = Proc.new do
# nice shortcut: Class[:first] eq Class.find(:first)
#ActiveRecord::Base.instance_eval { alias :[] :find }
#end
## helper.url_for.. got from: http://errtheblog.com/posts/41-real-console-helpers
#def Object.method_added(method)
# return super(method) unless method == :helper
# (class<<self;self;end).send(:remove_method, :method_added)
# def helper(*helper_names)
# returning $helper_proxy ||= Object.new do |helper|
# helper_names.each { |h| helper.extend "#{h}_helper".classify.constantize }
# end
# end
# helper.instance_variable_set("@controller", ActionController::Integration::Session.new)
# def helper.method_missing(method, *args, &block)
# @controller.send(method, *args, &block) if @controller && method.to_s =~ /_path$|_url$/
# end
# helper :application rescue nil
#end
end
# tracing support
################################################################################
def enable_trace( event_regex = /^(call|return)/, class_regex = /IRB|Wirble|RubyLex|RubyToken/ )
puts "Enabling method tracing with event regex #{event_regex.inspect} and class exclusion regex #{class_regex.inspect}"
level = 0
set_trace_func Proc.new{|event, file, line, id, binding, classname|
level += 1 if event == 'call'
if event =~ event_regex && classname.to_s !~ class_regex
file = File.expand_path(file)
# making relative
if file.index(Dir.pwd) == 0
file[Dir.pwd + '/'] = ''
end
printf "[%8s]%#{level}s %-#{[30-level, 0].max}s %-30s (%s:%-2d)\n", event, '', id, classname, file, line
end
level -= 1 if event == 'return'
}
return
end
def disable_trace
puts "Disabling method tracing"
set_trace_func nil
end
def debug
require 'ruby-debug'
debugger
yield
end