Last active
April 19, 2016 09:18
-
-
Save todokr/ac2fee4a860eec49dd236ceda08846f9 to your computer and use it in GitHub Desktop.
本番環境とかでiTermの文字や背景色を切り替える
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 | |
# 1. Save as ~/bin/ssh-color | |
# 2. chmod 755 ~/bin/ssh-color | |
# 3. alias ssh='~/bin/ssh-color' | |
# 4. change host name | |
# 5. ssh {your host name} | |
set_color() { | |
local hex_fg=$1 | |
local hex_bg=$2 | |
local transparency=$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 "$transparency" | |
end tell | |
end tell | |
EOF | |
} | |
# change to your host name | |
if [["$@" =~ production.com]]; then | |
set_color ffffff 220000 0.3 | |
elif [["$@" =~ development.co.jp]]; then | |
set_color ffffff 001100 0.5 | |
fi | |
ssh $@ | |
set_color ffffff 000000 0.2 # default termnal color |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment