Skip to content

Instantly share code, notes, and snippets.

@tadyjp
Created November 21, 2014 05:10
Show Gist options
  • Save tadyjp/4b75898d5ffa0d9fce3a to your computer and use it in GitHub Desktop.
Save tadyjp/4b75898d5ffa0d9fce3a to your computer and use it in GitHub Desktop.
...
alias ssh='~/bin/iterm2-set-background'
...
#!/bin/bash
# ~/bin/iterm2-set-background
# 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
}
# ここでホストによる色を決める
# 最初のffffffが文字色
# 次の330000が背景色
if [[ "$@" =~ xxxx.com ]]; then
set_color ffffff 330000 0.2
elif [[ "$@" =~ 192.128.88.88 ]]; 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