forked from ebeigarts/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirbrc
executable file
·67 lines (58 loc) · 1.89 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
# http://linux.die.net/man/1/irb
IRB.conf[:PROMPT_MODE] = :SIMPLE
# Check if RVM hasn't already loaded some history.
if Readline::HISTORY.size == 0
histfile = File.expand_path(".irb-history", ENV["HOME"])
if File.exists?(histfile)
lines = IO.readlines(histfile).collect { |line| line.chomp }
Readline::HISTORY.push("") if Readline::VERSION == "EditLine wrapper" # OS X native ruby?
Readline::HISTORY.push(*lines)
end
Kernel::at_exit do
maxhistsize = 100
histfile = File::expand_path(".irb-history", ENV["HOME"])
lines = Readline::HISTORY.to_a.reverse.uniq.reverse
lines = lines[-maxhistsize, maxhistsize] if lines.compact.length > maxhistsize
File::open(histfile, "w+") { |io| io.puts lines.join("\n") }
end
end
# Remove duplicates in history
module Readline
alias :old_readline :readline
def readline(*args)
line = old_readline(*args)
# Check history for duplicates
dups = []
Readline::HISTORY.each_with_index do |l, i|
dups << i if l == line
end
dups.reverse!
dups.each do |i|
# i += 1 if Readline::VERSION == "EditLine wrapper" # OS X native ruby?
Readline::HISTORY.delete_at(i)
end
# File.open("#{ENV['HOME']}/.irb-history", 'ab') { |f| f << "#{line}\n" }
line
end
end
def history
Readline::HISTORY.to_a
end
# Allow using these gems without adding them to bundler
$LOAD_PATH << "#{ENV['HOME']}/.gem/ruby/2.0.0/gems/hirb-0.7.0/lib"
$LOAD_PATH << "#{ENV['HOME']}/.gem/ruby/2.0.0/gems/awesome_print-1.1.0/lib"
begin
require "awesome_print"
AwesomePrint.irb!
rescue LoadError, NameError => e
$stderr.puts e.message
end
begin
require "hirb"
extend Hirb::Console
Hirb.enable :pager => false
Hirb.enable :formatter => false
rescue LoadError => e
$stderr.puts e.message
end
load File.dirname(__FILE__) + '/.railsrc' if $0 == 'script/rails' || $0 == 'rails_console' || ($0 == 'irb' && ENV['RAILS_ENV'])