Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the color of my Terminal.App when I log into my production remote on Heroku?

I remember there was an article, or a few, going around about how the author changes the color of the terminal from green (for development) to red (for production) based on the SSH address.

But I am not sure how to replicate that with Heroku console.

Ideally, I would like for it to be say blue, when I do heroku console --remote staging and then red, when I do heroku console --remote production.

Any suggestions anyone ?

like image 360
marcamillion Avatar asked Apr 18 '11 02:04

marcamillion


People also ask

How do I see Heroku console log?

You can view logs with the Heroku CLI, the dashboard, your logging add-on, or in your log drain. You can't view logs for apps in Shield spaces with Private Space Logging enabled. Retrieve logs from your log drain instead.

What is heroku log?

Simply use heroku logs to display the last 100 lines of your logs. Or to tail the logs in real-time: heroku logs -t. Heroku only saves the last 1500 lines of logs, which you can access using heroku logs -n 1500 . If you want more logging, check out Heroku add-ons like Logentries or Papertrail.


2 Answers

In any file that is loaded as part of the production environment (say, config/environments/production.rb), you can put:

if defined? IRB
  # whew!
  conf = IRB.conf[:PROMPT][IRB.conf[:PROMPT_MODE]]
  red = "\033[0;31m"
  reset = "\033[0m"
  conf[:PROMPT_S] = "#{red}>> #{reset}" # regular prompt
end

The crazy escape characters are ANSI color codes. The "\033" is an escape character, and the rest is a code for a particular color or effect. You can find a list of other colors and effects here. That IRB.conf hash is a global conf for IRB. You may want to set a few other keys on it - they're documented here.

If you're not using Rails (and hence don't necessarily have an environment file), you can always check the current environment by using ENV['RACK_ENV'], which should be set to 'production' on Heroku.

like image 126
Jay Adkisson Avatar answered Oct 15 '22 22:10

Jay Adkisson


I do this by using the Marco Polo gem https://github.com/arches/marco-polo

You can then change your console prompt by setting the heroku config variable MARCO_POLO_APP_NAME. You can take advantage of escape codes to change the color. In my case, I set the production prompt to be white on a magenta background (hard to miss) using this control sequence for the value of MARCO_POLO_APP_NAME

[ESC][105;97;1mPRODUCTION[ESC][0m

Unfortunately, Stack Overflow won't let me post the escape character itself. You'll have to use Notepad++ and run a Regexp search and replace to replace [ESC] above with \x1B. Then you can copy and paste into the value of MARCO_POLO_APP_NAME in the Heroku console. I couldn't manage to set it at the command line.

like image 25
ChaosFreak Avatar answered Oct 15 '22 22:10

ChaosFreak