LoginSignup
10
10

More than 5 years have passed since last update.

OSXからSSHでリモートサーバーにログインしてる時は背景色を変更する

Posted at

この前、さくらのVPSにいれたはずのアプリが入ってなかったのでインストールからやり直してたら何かおかしい。何がおかしいかしばらく考えてたら「これ、リモートじゃなくてローカルじゃないですかーー!!!」と悲しい思いをしたので、もうそんなことを無くすために対策を考えました。

SSH にログインしてる時は背景色をかえる。

というわけで「背景色を変えとけば多分気づくだろ。」という初めに思いついた対策を講じてみることにします。

~/bin をPATHの先頭に追加した状態で

~/bin/ssh
set_bg () {
  osascript -e "tell application \"Terminal\" to set background color of window 1 to $1"
}

on_exit () {
  set_bg "{65535, 65535,65535,65535}"
}
trap on_exit EXIT

case $HOSTNAME in
  production1|production2|production3) set_bg "{45000, 0, 0, 50000}" ;;
  *) set_bg "{45000, 55000, 60000, 50000}" ;;
esac

/usr/bin/ssh "$@"

しとくとOK.

基本背景色は白でリモートサーバー上は青っぽいのになってます。

参考

osx - How do I make the apple terminal window auto change colour scheme when I ssh to a specific server - Stack Overflow
http://stackoverflow.com/questions/157959/how-do-i-make-the-apple-terminal-window-auto-change-colour-scheme-when-i-ssh-to

10
10
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
10
10