LoginSignup
9
8

More than 5 years have passed since last update.

iTerm2 Build 3.0.4 で ssh 先毎に画面の色を変更する

Last updated at Posted at 2016-07-20

画面の色の変更

version 3.0 から Applescript による iTerm2 の操作方法が変更になりました.
新しいバージョンに対応したドキュメントによると, 以下の Applescript で変更可能になります.

tell application "iTerm2"
  tell current session of current window
    set background color to {$R, $G, $B}
  end tell
end tell

ちなみに,set background color to {$R, $G, $B, $alpha} といったように 4番目の引数 $alpha を渡すと透過度を変更できます.

ssh 毎に画面の色を変更する

例えば,自分は以下のように設定しています.

function set_term_bgcolor() {
  local R=${1}*65535/255
  local G=${2}*65535/255
  local B=${3}*65535/255

  /usr/bin/osascript <<EOF
  tell application "iTerm2"
    tell current session of current window
      set background color to {$R, $G, $B}
    end tell
  end tell
EOF
}

function myssh() {
 local R=0
 local G=0
 local B=0
 case $1 in
   "dev" ) R=40 G=0; B=0; shift ;;
   "pro" ) R=0; G=40; B=0; shift ;;
   "warn") R=40 G=40; B=0; shift ;;
   *) R=0; G=0; B=30 ;;
 esac
  set_term_bgcolor $R $G $B
  \ssh $@
  set_term_bgcolor 0 0 0
}

alias ssh='myssh'

以下のように使うことができます.

ssh dev host   # 背景赤
ssh pro host   # 背景緑
ssh warn host  # 背景黄色
ssh host       # 背景青

参考

iTermでsshするときに、接続先に応じて背景色を変える方法

9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8