Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Xterm-compatible Unix terminals have standard escape sequences for setting the background and foreground colors. I'm not sure if Terminal.app shares them; it should.</p> <pre><code>case $HOSTNAME in live1|live2|live3) echo -e '\e]11;1\a' ;; testing1|testing2) echo -e '\e]11;2\a' ;; esac </code></pre> <p>The second number specifies the desired color. 0=default, 1=red, 2=green, etc. So this snippet, when put in a shared .bashrc, will give you a red background on live servers and a green background on testing ones. You should also add something like this to reset the background when you log out.</p> <pre><code>on_exit () { echo -e '\e]11;0\a' } trap on_exit EXIT </code></pre> <hr> <p>EDIT: Google turned up a way to <a href="http://www.athensexchange.com/blog/155" rel="nofollow noreferrer">set the background color using AppleScript</a>. Obviously, this only works when run on the same machine as Terminal.app. You can work around that with a couple wrapper functions:</p> <pre><code>set_bg_color () { # color values are in '{R, G, B, A}' format, all 16-bit unsigned integers (0-65535) osascript -e "tell application \"Terminal\" to set background color of window 1 to $1" } sshl () { set_bg_color "{45000, 0, 0, 50000}" ssh "$@" set_bg_color "{0, 0, 0, 50000}" } </code></pre> <p>You'd need to remember to run sshl instead of ssh when connecting to a live server. Another option is to write a wrapper function for ssh that scans its arguments for known live hostnames and sets the background accordingly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload