Terminal displays directory of previous SSH location even when not running SSH

I am using the terminal app to ssh and when I do, it conveniently tells me (at the very top) what and where I am logged into for example:

user@computer:/home/user/directory/

and so forth. However, when I exit the ssh session and am sitting nicely at my local directory, it still tells me the directory path of the place I was previously logged in to.

Is there any way to have it tell me that information only when I am actually logged in to a remote machine? I have already gone to Terminal -> preferences -> profiles -> window and I only have "Dimensions" checked.


Taken wholesale from this SuperUser.com question and answer...

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.