How automatically change window name to the remote host name

427 views
Skip to first unread message

liuyuanting1209

unread,
Jan 7, 2018, 9:21:38 AM1/7/18
to tmux-...@googlegroups.com
Hi,

I want to change the window name to the remote ssh-to-host name. But I failed to find the way. host or host_short only show's the local "host" name. Could you please help to tell me the method. Thanks a lot.

Thanks,
Sean Liu 


 

Nicholas Marriott

unread,
Jan 7, 2018, 9:25:34 AM1/7/18
to liuyuanting1209, tmux-users
There are two ways to do this:

- You can turn on allow-rename and then use the rename window escape sequences (\033k...\033\\) to rename the window from the remote host (say in your .profile), for example: printf "\033k$(hostname -s)\033\\\\"

- You can write a script to do this from the local machine either using the same escape sequence, using tmux renamew, or putting it in say a user variable or environment variable that you can access from window-status-format, then aliasing that script to ssh.






 

--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+unsubscribe@googlegroups.com.
To post to this group, send email to tmux-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

liuyuanting1209

unread,
Jan 8, 2018, 8:04:51 AM1/8/18
to Nicholas Marriott, tmux-users

got it. thanks very much.

thanks,
Sean Liu

woosley. xu.

unread,
Jan 10, 2018, 9:07:10 AM1/10/18
to liuyuanting1209, Nicholas Marriott, tmux-users
I had this requirement also, and found such a solution by creating below ssh function in my .bashrc

function on_exit(){
    printf "\033kbash\033\\"
    tmux set-window-option automatic-rename on  >/dev/null 2>&1
    trap - SIGINT SIGTERM
}

function ssh() {
    if [ $TERM = "screen-256" ];then
        trap on_exit SIGINT SIGTERM
        a=${1##*@};
        printf "\033k$a\033\\"
        /usr/bin/ssh $@
        printf "\033kbash\033\\"
    else
        /usr/bin/ssh $@
    fi
    tmux set-window-option automatic-rename on  >/dev/null 2>&1
}
--
woosley.xu.    http://twitter.com/redicaps


Reply all
Reply to author
Forward
0 new messages