Skip to content

Commit

Permalink
Split irb config into separate files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Aug 22, 2012
1 parent 55e6845 commit e3d7f1d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
17 changes: 4 additions & 13 deletions irbrc
Expand Up @@ -3,19 +3,10 @@ require 'pp'

IRB.conf[:AUTO_INDENT] = true

class Array
def self.toy
[1, 2, 3] + %w(a b c)
def require_rb_files_from(dir)
Dir.glob(File.join(dir, '*.rb')) do |file|
require file
end
end

class Hash
def self.toy
{
1 => 2
'a' => 'b',
'foo' => 'bar',
:hello => 'there'
}
end
end
require_rb_files_from(File.join(ENV['HOME'], '.irbrc.d'))
1 change: 1 addition & 0 deletions irbrc.d/completion.rb
@@ -0,0 +1 @@
require 'irb/completion'
16 changes: 16 additions & 0 deletions irbrc.d/core_extensions.rb
@@ -0,0 +1,16 @@
class Array
def self.toy
[1, 2, 3] + %w(a b c)
end
end

class Hash
def self.toy
{
1 => 2
'a' => 'b',
'foo' => 'bar',
:hello => 'there'
}
end
end
24 changes: 24 additions & 0 deletions irbrc.d/history.rb
@@ -0,0 +1,24 @@
IRB.conf[:USE_READLINE] = true

module Readline
module History
LOG = "#{ENV["HOME"]}/.irb-save-history"
def self.write_log(line)
File.open(LOG, 'ab') {|f| f << "#{line}\n"} unless line == "exit"
end
end

alias :old_readline :readline
def readline(*args)
ln = old_readline(*args)
begin
History.write_log(ln)
rescue
end
ln
end
end

require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_FILE] = "#{ENV["HOME"]}/.irb-save-history"

0 comments on commit e3d7f1d

Please sign in to comment.