Created
January 10, 2011 20:49
-
-
Save yashh/773441 to your computer and use it in GitHub Desktop.
Automatically set your terminal color upon SSH to a host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Full credit to: http://jeffmiller.github.com/2011/01/10/ssh-host-color | |
#!/bin/bash | |
# | |
# ssh into a machine and automatically set the background | |
# color of Mac OS X Terminal depending on the hostname. | |
# | |
# Installation: | |
# 1. Save this script to /some/bin/ssh-host-color | |
# 2. chmod 755 /some/bin/ssh-host-color | |
# 3. alias ssh=/some/bin/ssh-host-color | |
# 4. Configure your host colors below. | |
set_term_bgcolor() { | |
local R=$1 | |
local G=$2 | |
local B=$3 | |
/usr/bin/osascript <<EOF | |
tell application "Terminal" | |
tell window 0 | |
set the background color to {$(($R*65535/255)), $(($G*65535/255)), $(($B*65535/255))} | |
end tell | |
end tell | |
EOF | |
} | |
# Host-specific background colors. | |
if [[ "$@" =~ production1.com ]]; then | |
set_term_bgcolor 127 0 0 | |
elif [[ "$@" =~ production2.com ]]; then | |
set_term_bgcolor 0 127 0 | |
fi | |
ssh $@ | |
# Default background color. | |
set_term_bgcolor 0 0 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment