-
-
Save KeithYJohnson/16ed42249319fbf811484ab6c5bdc60a to your computer and use it in GitHub Desktop.
Changes iTerm2's background color based on host configuration
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/bash | |
# Installation: | |
# 1. Save this script to /some/bin/ssh-background | |
# 2. chmod 755 /some/bin/ssh-background | |
# 3. alias ssh=/some/bin/ssh-background | |
# 4. Configure your host colors below. | |
set_color() { | |
local HEX_FG=$1 | |
local HEX_BG=$2 | |
local OPACITY=$3 | |
local FG_R=`echo $HEX_FG | sed 's/../0x&,/g' | awk -F "," '{printf("%d",$1 * 257)}'` | |
local FG_G=`echo $HEX_FG | sed 's/../0x&,/g' | awk -F "," '{printf("%d",$2 * 257)}'` | |
local FG_B=`echo $HEX_FG | sed 's/../0x&,/g' | awk -F "," '{printf("%d",$3 * 257)}'` | |
local BG_R=`echo $HEX_BG | sed 's/../0x&,/g' | awk -F "," '{printf("%d",$1 * 257)}'` | |
local BG_G=`echo $HEX_BG | sed 's/../0x&,/g' | awk -F "," '{printf("%d",$2 * 257)}'` | |
local BG_B=`echo $HEX_BG | sed 's/../0x&,/g' | awk -F "," '{printf("%d",$3 * 257)}'` | |
/usr/bin/osascript <<EOF | |
tell application "iTerm" | |
tell current session of first window | |
set foreground color to {$FG_R, $FG_G, $FG_B} | |
set background color to {$BG_R, $BG_G, $BG_B} | |
set transparency to "$OPACITY" | |
end tell | |
end tell | |
EOF | |
} | |
if [[ "$@" =~ ant.amazon ]]; then | |
set_color ffffff 330000 0.2 | |
elif [[ "$@" =~ dev-dsk ]]; then | |
set_color ffffff 000033 0.2 | |
else | |
set_color ffffff 000055 0.2 | |
fi | |
ssh $@ | |
set_color ffffff 000000 0.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment