Skip to content

Instantly share code, notes, and snippets.

@iiska
Created October 8, 2010 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iiska/616461 to your computer and use it in GitHub Desktop.
Save iiska/616461 to your computer and use it in GitHub Desktop.
Command history, tab completion and Rails SQL logs for script/console
# -*- mode: ruby -*-
# TAB completion for irb
require 'irb/completion'
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
# Save command history to be used between multiple sessions
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
# Output Rails logs to stdout when using script/console
script_console_running = ENV.include?('RAILS_ENV') && IRB.conf[:LOAD_MODULES] && IRB.conf[:LOAD_MODULES].include?('console_with_helpers')
rails_running = ENV.include?('RAILS_ENV') && !(IRB.conf[:LOAD_MODULES] && IRB.conf[:LOAD_MODULES].include?('console_with_helpers'))
irb_standalone_running = !script_console_running && !rails_running
if script_console_running
require 'logger'
Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment