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

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


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 promptend

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.


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.


untested, but something along the lines of this in your .bashrc or whatever may be what you want (it's not completely safe but you should get the idea)

function heroku {  REMOTE_TERMINAL_THEME_NAME="Solarized Light"  CURTAB=$(osascript -e "tell application \"Terminal\" to get the selected tab of the front window")  CURTHEME=$(osascript -e "tell application \"Terminal\" to get the name of current settings of the selected tab of the front window")  HEROKU=$(which heroku)  osascript -e "tell application \"Terminal\" to set current settings of $CURTAB to settings set \"$REMOTE_TERMINAL_THEME_NAME\""  $HEROKU "$@"  osascript -e "tell application \"Terminal\" to set current settings of $CURTAB to settings set  \"$CURTHEME\""}

I use it for ssh but it's conceptually the same: override your command with a function that uses osascript to change the terminal settings, then change them back on exit. Switching based on arguments should be relatively easy to add.