Skip to content

Instantly share code, notes, and snippets.

@marcinbunsch
Created June 24, 2011 08:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marcinbunsch/1044437 to your computer and use it in GitHub Desktop.
Save marcinbunsch/1044437 to your computer and use it in GitHub Desktop.
Rails production prompt change as a Rails initializer
# Put this file in config/initializers/irb.rb
# Works in Rails 3.0+, should also work in 2.3
# Override the IRB, to provide the Rails environment in the prompt
module IRB
class << self
def setup_with_prompt_override(ap_path)
setup_without_prompt_override(ap_path)
env = (Rails.env.to_sym == :production ? "\033[00;31mPRODUCTION\033[00m" : Rails.env)
IRB.conf[:PROMPT].keys.each do |prompt|
IRB.conf[:PROMPT][prompt][:PROMPT_I] = "(#{env}) " + IRB.conf[:PROMPT][prompt][:PROMPT_I].to_s
IRB.conf[:PROMPT][prompt][:PROMPT_C] = "(#{env}) " + IRB.conf[:PROMPT][prompt][:PROMPT_C].to_s
IRB.conf[:PROMPT][prompt][:PROMPT_S] = "(#{env}) " + IRB.conf[:PROMPT][prompt][:PROMPT_S].to_s
end
end
alias_method_chain :setup, :prompt_override
end
end
@mgates
Copy link

mgates commented Apr 12, 2013

FYI, this will break production 'rails s' in (at least) 3.2.8. Adding 'require IRB' before it makes it work.

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