Skip to content

Instantly share code, notes, and snippets.

@aputs
Created April 12, 2010 16:30
Show Gist options
  • Save aputs/363752 to your computer and use it in GitHub Desktop.
Save aputs/363752 to your computer and use it in GitHub Desktop.
irb with auto completion
require 'irb/completion'
require 'irb/ext/save-history'
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
module Readline
module History
LOG = "#{ENV['HOME']}/.irb-history"
def self.write_log(line)
File.open(LOG, 'ab') {|f| f << "#{line}
"}
end
def self.start_session_log
write_log("
# session start: #{Time.now}
")
at_exit { write_log("
# session stop: #{Time.now}
") }
end
end
alias :old_readline :readline
def readline(*args)
ln = old_readline(*args)
begin
History.write_log(ln)
rescue
end
ln
end
end
Readline::History.start_session_log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment