Skip to content

Instantly share code, notes, and snippets.

@pawurb
Created February 23, 2020 12:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawurb/0ef8ac5e34312c0a135ab62f621dc7c4 to your computer and use it in GitHub Desktop.
Save pawurb/0ef8ac5e34312c0a135ab62f621dc7c4 to your computer and use it in GitHub Desktop.
Rails colored prompt without gems
# config/application.rb
module RailsApplicationName
class Application < Rails::Application
...
console do
ARGV.push "-r", root.join("lib/console.rb")
end
end
end
# lib/console.rb
app = "App name"
env = Rails.env
env_color = Rails.env.production? ? "\e[31m#{env}\e[0m" : env # Red (31) if production environment
IRB.conf[:PROMPT] ||= {}
IRB.conf[:PROMPT][:RAILS_APP] = {
PROMPT_I: "#{app} (#{env_color}) > ",
PROMPT_N: nil,
PROMPT_S: nil,
PROMPT_C: nil,
RETURN: "=> %s\n"
}
# Use the custom prompt
IRB.conf[:PROMPT_MODE] = :RAILS_APP
unless Rails.env.production?
# Save commands in `~/.app-env-irb-history`
IRB.conf[:HISTORY_FILE] = File.expand_path("~/.#{app}-#{env}-irb-history")
# Save 2000 lines of command history
IRB.conf[:SAVE_HISTORY] = 2000
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment