-
Notifications
You must be signed in to change notification settings - Fork 1
/
irbrc
59 lines (49 loc) · 1.6 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
#!/usr/bin/env ruby
require "rubygems"
require "ftools"
# http://pablotron.org/software/wirble/
# Colorizes output, adds history etc.
begin
require 'wirble'
Wirble.init
Wirble.colorize
rescue LoadError => e
warn "Couldn't load Wirble: #{e}"
end
# http://vimcasts.org/episodes/running-vim-within-irb/
# Type "vim" or "mvim" in irb to edit in Vim.
begin
require 'interactive_editor'
rescue LoadError => e
warn "Couldn't load interactive_editor: #{e}"
end
# Quick benchmarking
# http://stackoverflow.com/questions/123494/whats-your-favourite-irb-trick/123834#123834
def bench(repetitions=100, &block)
require 'benchmark'
Benchmark.bmbm do |b|
b.report {repetitions.times &block}
end
nil
end
# Pre-defined hash and array to experiment with.
# http://stackoverflow.com/questions/123494/whats-your-favourite-irb-trick/123847#123847
HASH = { :one => 1, :two => 2, :three => 3, :four => 4, :five => 5 } unless defined?(HASH)
ARRAY = %w[one two three four five] unless defined?(ARRAY)
# Enable lambda prompts. http://twitter.com/acetoxy/status/26734736005
class IRB::Irb
alias :original_prompt :prompt
def prompt(prompt, ltype, indent, line_no)
prompt = prompt.call if prompt.respond_to?(:call)
original_prompt(prompt, ltype, indent, line_no)
end
end
# E.g.:
# 12:23:15 >>
# DEV 12:23:15 >>
IRB.conf[:PROMPT][:SIMPLE].merge!(:PROMPT_I => lambda {
"#{[ ENV['RAILS_ENV'] && Rails.env.first(3).upcase, Time.now.strftime("%H:%M:%S") ].compact.join(' ')} >> "
})
IRB.conf[:PROMPT_MODE] = :SIMPLE
# Load .railsrc for Rails.
load File.dirname(__FILE__) + '/.railsrc' if $0 == 'irb' && ENV['RAILS_ENV']