Skip to content

Instantly share code, notes, and snippets.

@iganari
Forked from BugRoger/ssh-background
Created July 22, 2014 15:13
Show Gist options
  • Save iganari/2ed7f551792285e54fea to your computer and use it in GitHub Desktop.
Save iganari/2ed7f551792285e54fea to your computer and use it in GitHub Desktop.
#!/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 current terminal
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 [[ "$@" =~ host0.example.com ]]; then
set_color ffffff 330000 0.2
elif [[ "$@" =~ host1.example.com ]]; then
set_color ffffff 000033 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