From cff320980b641724f0e9f46c8704450e7223ac70 Mon Sep 17 00:00:00 2001 From: Jon Allured Date: Wed, 15 Apr 2020 11:41:02 -0500 Subject: [PATCH 1/2] Extract locals for each part of the prompt --- lib/console_color/railtie.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/console_color/railtie.rb b/lib/console_color/railtie.rb index 62b6538..dd035d9 100644 --- a/lib/console_color/railtie.rb +++ b/lib/console_color/railtie.rb @@ -4,7 +4,12 @@ module IRBSetup def setup(*) super - prompt = "\001#{ConsoleColor::COLORS[Rails.env]}\002#{Rails.application.class.parent_name.downcase}:#{Rails.env}" + app_name = Rails.application.class.parent_name.downcase + environment = Rails.env + color = ConsoleColor::COLORS[environment] + + prompt = "\001#{color}\002#{app_name}:#{environment}" + IRB.conf[:PROMPT][:RAILS_APP] = { PROMPT_I: "#{prompt}>\e[0m ", PROMPT_N: "#{prompt}>\e[0m ", @@ -13,6 +18,7 @@ def setup(*) RETURN: "=> %s\n", AUTO_INDENT: true } + IRB.conf[:PROMPT_MODE] = :RAILS_APP end end From 40875dc80019040fc44af1301d682260b2af70c2 Mon Sep 17 00:00:00 2001 From: Jon Allured Date: Wed, 15 Apr 2020 11:48:27 -0500 Subject: [PATCH 2/2] Support separate var for console color --- README.md | 12 ++++++++++++ lib/console_color/railtie.rb | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e336a6..1fe46d5 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,18 @@ By default, the prompt is green in development, red in production, and yellow el ConsoleColor::COLORS['production'] = "\e[35m" # pink +Note that one can set the `CONSOLE_COLOR_ENV` var to override the Rails +environment: + +``` +$ CONSOLE_COLOR_ENV=staging RAILS_ENV=production rails console +app_name:staging>Rails.env +=> "production" +``` + +This way you can set your staging Rails env to production to mimic that +configuration but have your prompt reflect that you're using on the staging +server. ## Installation diff --git a/lib/console_color/railtie.rb b/lib/console_color/railtie.rb index dd035d9..0dbf859 100644 --- a/lib/console_color/railtie.rb +++ b/lib/console_color/railtie.rb @@ -5,7 +5,7 @@ def setup(*) super app_name = Rails.application.class.parent_name.downcase - environment = Rails.env + environment = ENV.fetch('CONSOLE_COLOR_ENV', Rails.env) color = ConsoleColor::COLORS[environment] prompt = "\001#{color}\002#{app_name}:#{environment}"