-
Notifications
You must be signed in to change notification settings - Fork 0
/
irbrc
114 lines (94 loc) · 2.29 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
begin
require "bond"
Bond.start
rescue LoadError
require "irb/completion"
end
begin
require "pry-toys"
rescue LoadError
end
require "pp"
require "rubygems"
def i(*m) include *m; end
def j; jobs; end
def q!; quit; end
def r!; reload! end
# r:some_thang
# r "some/thang"
def r(lib)
require lib.to_s
end
def echo!
conf.echo = !conf.echo
end
def prompt(name, version)
sprintf "%s [%s] (%s)$ ", name, version, File.basename(Dir.pwd)
end
def cd(path = nil)
path ||= Dir.home
path = path == "-" && $__dirstack ? $__dirstack : File.expand_path(path)
# maybe more $DIRSTACK like one day...
pwd = Dir.pwd
Dir.chdir(path)
$__dirstack = pwd
path
end
def self.method_missing(name, *args)
system name.to_s, *args
# TODO: Win???
# Would be nice to echo nothing
$?.exitstatus == 127 ? super : $?.exitstatus
end
versions = {
"jruby" => "jirb",
"macruby" => "macirb",
"rbx" => "irbx",
"ree" => "irbee"
}
target = Object.const_defined?("RUBY_ENGINE") ? RUBY_ENGINE : RUBY_PLATFORM
irbname = versions.fetch(target,"irb")
IRB.conf[:SAVE_HISTORY] = 10_000
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:PROMPT][:CUSTOM] = {
:PROMPT_I => prompt(irbname, RUBY_VERSION),
:PROMPT_C => "%i* ",
:PROMPT_N => "%i{ ",
:PROMPT_S => "%i%l ",
:RETURN => "=> %s\n"
}
# We probably care about irbname here
custom = IRB.conf[:PROMPT][:CUSTOM]
if defined?(Rails)
name = "rails"
name << "-#{Rails.env}" unless Rails.env.development?
custom[:PROMPT_I] = prompt(name, Rails.version)
elsif defined?(Padrino)
name = "padrino"
name << "-#{ENV["RACK_ENV"]}" unless ENV["RACK_ENV"] == "development"
custom[:PROMPT_I] = prompt(name, Padrino.version)
end
IRB.conf[:PROMPT_MODE] = :CUSTOM
if defined?(ActiveRecord) || defined?(Moped)
require "logger"
logger = Logger.new(STDERR)
if defined?(Moped)
Moped.logger = logger
else
begin
require "hirb"
extend Hirb::Console
rescue LoadError
end
ActiveRecord::Base.logger = logger
if File.exists?("NUL") # Too lazy now...
if defined?(ActiveSupport::LogSubscriber)
ActiveSupport::LogSubscriber.colorize_logging = false
else
ActiveRecord::Base.colorize_logging = false
end
end
end
end
local = File.join(Dir.pwd, ".irbrc")
load local if local != __FILE__ && File.exists?(local)