Restore Mac OS X Terminal title after closing a SSH connection

6,568

It's not an SSH issue. The issue is that the shell on the remote host is configured to send an escape sequence to set the terminal window title. This is a fairly common setup. The solutions mentioned in the blog post you linked to are correct.

The simplest and most direct solution is to configure that same remote shell to reset the window title when it logs out. e.g., if the remote shell is bash, put this in ~/.bash_logout:

printf '\e]0;\a'

Alternatively, if you'd like to have your local shell update the window title with something useful, anyway, then do that. When the ssh connection ends, the local shell will set the window title to something else instead of leaving the stale value. e.g. put this in ~/.bashrc:

PS1='\[\e]1;\s\$ \W\a\e]2;\u@\h\a\]'"$PS1"

This puts the user and host name in the window title (which is typically what remote shells are configured to do), and also sets the tab title to show the shell name and type (normal user or root) and current working directory.

Note that if you don't already have a ~/.bash_profile (or ~/.profile), create one and have it run ~/.bashrc so that ~/.bashrc applies to login and non-login shells:

if [ -f $HOME/.bashrc ]; then
    . $HOME/.bashrc
fi
Share:
6,568

Related videos on Youtube

elitalon
Author by

elitalon

Updated on September 18, 2022

Comments