Skip to content

Instantly share code, notes, and snippets.

@ibanez270dx
Last active August 29, 2015 14:21
Show Gist options
  • Save ibanez270dx/4d90c6e02b3a210268fb to your computer and use it in GitHub Desktop.
Save ibanez270dx/4d90c6e02b3a210268fb to your computer and use it in GitHub Desktop.
colors for remote sessions
#!/bin/bash
###########################
# AppleScripts
###########################
# Change the background color and alpha of the current terminal window (formatted to be the same as RGBA).
function iterm_bg {
local R=$1
local G=$2
local B=$3
local A=`ruby -e "print 1.0 - $4"`
/usr/bin/osascript <<EOF
tell application "iTerm"
tell the current terminal
tell the current session
set background color to {$(($R*65535/255)), $(($G*65535/255)), $(($B*65535/255))}
set transparency to "$A"
end tell
end tell
end tell
EOF
}
# Change the foreground color (default text color) of the current terminal window.
function iterm_fg {
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 foreground color to {$(($R*65535/255)), $(($G*65535/255)), $(($B*65535/255))}
end tell
end tell
end tell
EOF
}
###########################
# Color Wrapper
###########################
# Wrap the call to SSH
function ssh_color_wrapper() {
for param in "$@"; do
if [[ $param == *"@"* ]]; then
target=(${param//@/ });
domain=${target[1]};
if [[ $domain == "humani.se" ]]; then
iterm_bg 0 25 50 0.8;
iterm_fg 200 200 200;
fi
if [[ $domain == "69.90.132.48" ]]; then
iterm_bg 241 196 15 0.9
iterm_fg 0 0 0
fi
fi
done
ssh $@;
iterm_bg 0 0 0 0.75
iterm_fg 200 200 200
}
alias ssh=ssh_color_wrapper;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment