Skip to content

Commit

Permalink
Merge pull request joeyAghion#5 from jonallured/support-separate-colo…
Browse files Browse the repository at this point in the history
…r-var

Support separate color var
  • Loading branch information
joeyAghion authored Apr 17, 2020
2 parents ddbe27c + 40875dc commit f99dce1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion lib/console_color/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ENV.fetch('CONSOLE_COLOR_ENV', 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 ",
Expand All @@ -13,6 +18,7 @@ def setup(*)
RETURN: "=> %s\n",
AUTO_INDENT: true
}

IRB.conf[:PROMPT_MODE] = :RAILS_APP
end
end
Expand Down

0 comments on commit f99dce1

Please sign in to comment.