Last active
October 12, 2018 04:33
-
-
Save X0nic/e132600037c4de091eac11d179932113 to your computer and use it in GitHub Desktop.
How can I make the rails console prompt standout in production?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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