Created
June 21, 2014 16:33
-
-
Save mercul3s/e76555ed8cd969d4c42c to your computer and use it in GitHub Desktop.
SSH host colors
This file contains 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
#!/bin/sh | |
# | |
# ssh into a machine and automatically set the background | |
# color of Mac OS X iTerm depending on the hostname. | |
# | |
# Installation: | |
# 1. Save this script to /your_script_location/ssh-host-color.sh | |
# 2. chmod 755 /your_script_location/ssh-host-color.sh | |
# 3. alias ssh=/your_script_location/ssh-host-color.sh (add this to .bash_profile) | |
# 4. Configure your host colors below. | |
set_term_bgcolor() { | |
local R=$1 | |
local G=$2 | |
local B=$3 | |
/usr/bin/osascript <<EOF | |
tell application "iTerm" | |
tell the current terminal | |
tell the current session | |
set the background color to {$(($R*65535/255)), $(($G*65535/255)), $(($B*65535/255))} | |
end tell | |
end tell | |
end tell | |
EOF | |
} | |
# Host-specific background colors. | |
# the first is blue: | |
if [[ "$@" =~ <HOSTNAME> ]]; then | |
set_term_bgcolor 15 80 100 | |
# and this one should be red: | |
elif [[ "$@" =~ <HOSTNAME> ]]; then | |
set_term_bgcolor 124 10 2 | |
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