Skip to content

Instantly share code, notes, and snippets.

@swanson
Last active March 3, 2024 17:14
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save swanson/3ca98caff43d52f62b4b99f6f2c7444c to your computer and use it in GitHub Desktop.
Save swanson/3ca98caff43d52f62b4b99f6f2c7444c to your computer and use it in GitHub Desktop.
.irbrc color coding Rails console by environment
# Add color coding based on Rails environment for safety
if defined? Rails
banner = if Rails.env.production?
"\e[41;97;1m #{Rails.env} \e[0m "
else
"\e[42;97;1m #{Rails.env} \e[0m "
end
# Build a custom prompt
IRB.conf[:PROMPT][:CUSTOM] = IRB.conf[:PROMPT][:DEFAULT].merge(
PROMPT_I: banner + IRB.conf[:PROMPT][:DEFAULT][:PROMPT_I],
)
# Use custom prompt by default
IRB.conf[:PROMPT_MODE] = :CUSTOM
end
@swanson
Copy link
Author

swanson commented Jan 6, 2021

Relevant "docs" for customizing the IRB prompt: https://github.com/ruby/irb/blob/master/lib/irb.rb#L144-L233

@elalemanyo
Copy link

elalemanyo commented Nov 27, 2023

Thanks for sharing ❤️
Here is just a small suggestion, just wanted to contribute 🙂

  banner = "\e[#{Rails.env.production? ? "41" : "42"};97;1m #{Rails.env} \e[0m "

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