Skip to content

Instantly share code, notes, and snippets.

@douglasdollars
Created March 26, 2013 01:29
Show Gist options
  • Save douglasdollars/5242393 to your computer and use it in GitHub Desktop.
Save douglasdollars/5242393 to your computer and use it in GitHub Desktop.
irbrc and related Requires/works best with awesome_print and hirb
# awesome print
begin
require 'awesome_print'
AwesomePrint.irb!
rescue LoadError => err
warn "Couldn't load awesome_print: #{err}"
end
# configure irb
# Prompt mode simple just makes prompts look like >> instead of 1.9.3p327 :001 >
IRB.conf[:PROMPT_MODE] = :SIMPLE
# irb history
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
IRB.conf[:EVAL_HISTORY] = 1000
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_FILE] = File::expand_path("~/.irbhistory")
# load .irbrc_rails in rails environments
railsrc_path = File.expand_path('~/.irbrc_rails')
if ( ENV['RAILS_ENV'] || defined? Rails ) && File.exist?( railsrc_path )
begin
load railsrc_path
rescue Exception
warn "Could not load: #{ railsrc_path } because of #{$!.message}"
end
end
# hirb: some nice stuff for Rails
begin
require 'hirb'
HIRB_LOADED = true
rescue LoadError
HIRB_LOADED = false
end
require 'logger'
def loud_logger
enable_hirb
set_logger_to Logger.new(STDOUT)
end
def quiet_logger
disable_hirb
set_logger_to nil
end
def set_logger_to(logger)
ActiveRecord::Base.logger = logger
ActiveRecord::Base.clear_reloadable_connections!
end
def enable_hirb
if HIRB_LOADED
Hirb::Formatter.dynamic_config['ActiveRecord::Base']
Hirb.enable
else
puts "hirb is not loaded"
end
end
def disable_hirb
if HIRB_LOADED
Hirb.disable
else
puts "hirb is not loaded"
end
end
# set a nice prompt
rails_root = File.basename(Dir.pwd)
IRB.conf[:PROMPT] ||= {}
IRB.conf[:PROMPT][:RAILS] = {
:PROMPT_I => "#{rails_root}> ", # normal prompt
:PROMPT_S => "#{rails_root}* ", # prompt when continuing a string
:PROMPT_C => "#{rails_root}? ", # prompt when continuing a statement
:RETURN => "=> %s\n" # prefixes output
}
IRB.conf[:PROMPT_MODE] = :RAILS
# turn on the loud logging by default
IRB.conf[:IRB_RC] = Proc.new { loud_logger }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment