Restore Mac OS X Terminal title after closing a SSH connection

18

6

Possible Duplicate:
How do I make OS X set the terminal title back to the original title when coming back from ssh?

Every time you logout from a SSH connection in Mac OS X terminal you end up with the past login information in the window title.

Most solutions I have found searching on the web involves playing around con escape sequences, like this question or this related blog post.

It seems to be a SSH issue, not a Terminal thing, so I was wondering if there is an easier way of doing this (maybe editing SSH client configuration?).

elitalon

Posted 2011-09-26T08:07:33.290

Reputation: 365

Question was closed 2012-09-01T22:28:21.507

Answers

26

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

Chris Page

Posted 2011-09-26T08:07:33.290

Reputation: 2 793