Created
February 23, 2020 12:20
-
-
Save pawurb/0ef8ac5e34312c0a135ab62f621dc7c4 to your computer and use it in GitHub Desktop.
Rails colored prompt without gems
This file contains hidden or 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 | |
module RailsApplicationName | |
class Application < Rails::Application | |
... | |
console do | |
ARGV.push "-r", root.join("lib/console.rb") | |
end | |
end | |
end |
This file contains hidden or 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 | |
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