Skip to content

Instantly share code, notes, and snippets.

@X0nic
Last active October 12, 2018 04:33
Show Gist options
  • Save X0nic/e132600037c4de091eac11d179932113 to your computer and use it in GitHub Desktop.
Save X0nic/e132600037c4de091eac11d179932113 to your computer and use it in GitHub Desktop.
How can I make the rails console prompt standout in production?
# config/application.rb
class Application < Rails::Application
console do
console_settings = File.join(Rails.root, "lib/console.rb")
if File.exists?(console_settings)
puts "Loading lib/console.rb ..."
ARGV.push "-r", root.join("lib/console.rb")
end
end
end
# lib/console.rb
require 'irb/completion'
def colorize_env(env)
colors = {"production" => "31","development" => "32", "staging" => "33"}
color_code = colors[env]
return "\033[#{color_code}m#{env}\033[0m"
end
app = Rails.application.class.name.split('::').first
env = Rails.env
prompt = "[%i] [#{app}][#{colorize_env(env)}] %N(%m)"
IRB.conf[:PROMPT] ||= {}
IRB.conf[:PROMPT][:RAILS] = {
PROMPT_I: "#{prompt}> ",
PROMPT_N: "#{prompt}> ",
PROMPT_S: "#{prompt}%l ",
PROMPT_C: "#{prompt}* ",
RETURN: "=> %s\n"
}
IRB.conf[:PROMPT_MODE] = :RAILS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment