Skip to content

Instantly share code, notes, and snippets.

@JasonOffutt
Created June 28, 2011 17:21
Show Gist options
  • Save JasonOffutt/1051653 to your computer and use it in GitHub Desktop.
Save JasonOffutt/1051653 to your computer and use it in GitHub Desktop.
Ruby script to get the RawLine gem included in irb
#!/usr/local/bin/ruby -w
require 'rubygems'
require 'rawline'
puts "*** Inline Editor Test Shell ***"
puts " * Press CTRL+X to exit"
puts " * Press CTRL+C to clear command history"
puts " * Press CTRL+D for line-related information"
puts "Press CTRL+E to view command history"
editor = RawLine::Editor.new
editor.bind(:ctrl_c) { editor.clear_history }
editor.bind(:ctrl_d) { editor.debug_line }
editor.bind(:ctrl_e) { editor.show_history }
editor.bind(:ctrl_x) { puts; puts "Exiting..."; exit }
editor.completion_proc = lambda do |word|
if word
['select', 'update', 'delete', 'debug', 'destroy'].find_all { |e| e.match(/^#{Regexp.escape(word)}/) }
end
end
loop do
puts "You typed: [#{editor.read("=> ").chomp!}]"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment