0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

iTerm2でどのサーバーに接続しているかわかりやすくする方法

0
Last updated at Posted at 2026-06-23

.zshrc(bash なら .bashrc)に貼るだけ:

ssh() {
  # 接続コマンドをバッジに表示("ssh xxxxx" の"xxxx"がそのまま出る)
  local badge
  badge=$(printf '%s' "${@: -1}" | base64 | tr -d '\n')
  printf '\e]1337;SetBadgeFormat=%s\a' "$badge"

  command ssh "$@"

  # 切断したらバッジをクリア(exit code に関係なく必ず通る)
  printf '\e]1337;SetBadgeFormat=%s\a' "$(printf '' | base64)"
}

再起動後、右上にデカデカとxxxxと出ます

オプションについては除外していますが、下記でオプション付きやssh付きにもできます。

ssh() {
  # 接続コマンドをバッジに表示("ssh xxxxx"がそのまま出る)
  local badge
  badge=$(printf '%s' "ssh $*" | base64 | tr -d '\n')
  printf '\e]1337;SetBadgeFormat=%s\a' "$badge"

  command ssh "$@"

  # 切断したらバッジをクリア(exit code に関係なく必ず通る)
  printf '\e]1337;SetBadgeFormat=%s\a' "$(printf '' | base64)"
}

これはバッジを使っているため、バッジの設定でフォントサイズ、マージンを調整可能です。
設定箇所:
Preferences > Profiles > General の Badge

本来は接続先のホスト名そのものを変えるべきですが!
現場の最適解は上記かなと、、、!

良いインフラライフを!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?