Last active
December 22, 2015 23:19
-
-
Save numa08/6545981 to your computer and use it in GitHub Desktop.
SSH接続時にリモートホストの名前をペインのタイトルに設定する
This file contains hidden or 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
# https://www.spatof.org/blog/tmux-ssh-rename-window.html | |
ssh() { | |
if [[ $# == 0 || -z $TMUX ]]; then | |
command ssh $@ | |
fi | |
local remote=${${(P)#}%.*} | |
local old_name="$HOST" #現在のペインのタイトルを取得する方法がわかりません>_< しょうがないので、初期値のホスト名を指定 | |
local renamed=0 | |
if [[ $remote != -* ]]; then | |
renamed=1 | |
#tmux rename-window $remote | |
printf '\033]2;%s\033\\' "${remote}" | |
fi | |
command ssh $@ | |
if [[ $renamed == 1 ]];then | |
#tmux rename-window "$old_name" | |
printf '\033]2;%s\033\\' "${old_name}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment