Rename tmux window name to prompt_command, ps1 or remote ssh hostname?

I would love to be able to have my tmux window title automatically renamed to prompt_command, ps1 or just the hostname of a machine I ssh to. having 9 windows opened labeled “ssh” is really useless. Doing sysadmin work I open new screens and ssh around to much to manually rename them.

One thing I noticed is tmux updates the xterm window title so I feel like it has to know.

Any help? I would even be willing to go back to screen if I could get this feature.

Solution:

I’m not aware of any way to make it look at your PS1 directly.

However, tmux understands the same commands to set the window name as screen does.

So you can define a function like this in your ~/.bashrc or ~/.zshrc:

settitle() {    printf "33k$133\"}

and then call settitle from anywhere.

For example, you could include it in your PS1 variable, e.g.

PS1='$HOST:$PWD$(settitle $HOST:$PWD)$ '

or via PROMPT_COMMAND:

PROMPT_COMMAND='$(settitle $HOST:$PWD)'# and don't change PS1

Now I understand you have tmux running on your desktop, and you want ssh commands to have the hostname rather than ssh, that’s much easier.

Given you’ve added settitle to your local ~/.bashrc, all you want to do is add this too:

ssh() {    settitle "$*"    command ssh "$@"    settitle "bash"}

Replace bash with zsh, or something else more appropriate if necessary.