Skip to content

Instantly share code, notes, and snippets.

@arches
Created July 19, 2012 02:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arches/3140457 to your computer and use it in GitHub Desktop.
Save arches/3140457 to your computer and use it in GitHub Desktop.
Run a project-specific IRB config in Rails 3.1+
if ENV['RAILS_ENV']
rails_env = ENV['RAILS_ENV'].downcase
elsif Rails and Rails.env
rails_env = Rails.env.downcase
end
if rails_env
current_app = "myapp"
black = "\[\033[0;30m\]"
red = "\[\033[0;31m\]"
green = "\[\033[0;32m\]"
yellow = "\[\033[0;33m\]"
blue = "\[\033[0;34m\]"
purple = "\[\033[0;35m\]"
cyan = "\[\033[0;36m\]"
reset = "\[\033[0;0m\]"
environment_color = case rails_env
when 'development'
green
when 'staging'
yellow
when 'production'
red
else
red
end
rails_env = {'development' => 'dev', 'staging' => 'staging', 'production' => 'prod'}.fetch(rails_env) { 'unknown' }
IRB.conf[:PROMPT][:RAILS_ENV] = {
:PROMPT_I => "#{green}#{current_app}#{environment_color}(#{rails_env})#{reset}> ",
:PROMPT_N => "#{green}#{current_app}#{environment_color}(#{rails_env})#{reset}> ",
:PROMPT_S => nil,
:PROMPT_C => "?> ",
:RETURN => "=> %s\n"
}
IRB.conf[:PROMPT_MODE] = :RAILS_ENV
end
# Works on Heroku!
module MyAppName
class Application < Rails::Application
def load_console(app=self)
super
ARGV.push "-r", File.join(Rails.root, ".irbrc.rb")
end
end
end
@kerrizor
Copy link

Make this a gem.

@arches
Copy link
Author

arches commented Jul 20, 2012 via email

@kerrizor
Copy link

I'm on it.. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment