[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Tab Title when using ssh - Mate Terminal



On Tue, Sep 16, 2025 at 12:04:00 +0800, jeremy ardley wrote:
> I use Mate terminal and often ssh to different systems using multiple tabs
> 
> Usually the tab title changes to the new system when I ssh in, but often it
> doesn't revert when I exit.
> 
> Is there any way to make this work consistently?

It's all just hacks.  Setting the terminal's title is done by sending an
escape sequence to the terminal.  If your terminal follows the same codes
as xterm, you can use this bash function to set the title to whatever
you want:

title () 
{ 
    printf '\e]2;%s\a' "$*"
}

That's the easy part.  The hard part is getting that to happen when
you exit from an ssh session.  There are really only two places that
knows this is happening: the login shell on the remote server, and
the ssh client on the local system.

So, this gives us two possible approaches:

 1) Put something in the ~/.bash_logout file on the remote server which
    resets the terminal title to a neutral string.  You could conceivably
    look for the SSH_CLIENT variable here, and use that to generate a
    string that refers to the client hostname, but that's up to you.

 2) Wrap the ssh client in a script or function that rewrites the terminal
    title after the real /usr/bin/ssh command exits.

And I'll toss out a third option as well:

 3) Add something to your shell prompt (PS1 variable) on the client
    system which overwrites the terminal title every time the prompt
    is displayed.
    
This third one's the easiest, perhaps, but some folks might say it
lacks elegance.


Reply to: