My configuration for IRB: highlight Rails.env

1 min read

Never forget the environment you are in.
# .irbrc
module ColorString
refine String do
def cyan = "\e[36m#{self}\e[0m"
def bg_red = "\e[41m#{self}\e[0m"
def bg_yellow = "\e[43m#{self}\e[0m"
def bg_green = "\e[42m#{self}\e[0m"
end
end
if defined?(Rails)
using ColorString
if Rails.env.production? || Rails.env.staging?
IRB.conf[:SAVE_HISTORY] = false
end
project_name = File.basename(Dir.pwd).cyan
environment = case Rails.env
when "development"
Rails.env.bg_green
when "staging"
Rails.env.bg_yellow
when "production"
Rails.env.bg_red
end
prompt = "#{project_name} [#{environment}]"
IRB.conf[:PROMPT] ||= {}
IRB.conf[:PROMPT][:RAILS] = {
PROMPT_I: "#{prompt} %03n > ",
PROMPT_S: "#{prompt} %03n * ",
PROMPT_C: "#{prompt} %03n ? ",
RETURN: "=> %s\n"
}
IRB.conf[:PROMPT_MODE] = :RAILS
end
begin
require "awesome_print"
AwesomePrint.irb!
rescue
end
0
Subscribe to my newsletter
Read articles from Thomas Brennetot directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Thomas Brennetot
Thomas Brennetot
10+ years most with Ruby on Rails and JavaScript frontend and some Go. My first language is C for 3 years in university.