Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Mac OS X (I'm on 10.6.8, though I believe other versions are the same) ssh'ing into a remote machine changes the title of the current tab in Terminal. Annoyingly, when I disconnect from the remote machine, either explicitly with exit or via a timeout, the title of the tab doesn't change back to what it was.

On an almost daily basis this nearly causes me to suffer a heart attack, when I'm typing away performing some command or other, only to see out of the corner of my eye that the tab is still named user@remotehost. I'm a cautious user that always tends to pwd etc to confirm my location before doing anything, yet it still catches me in a moment of panic when I'm doing DROP DATABASE x and I see the remote host name in the tab.

Long story short, is there a way to revert this title when disconnecting from a remote host, or do I have to stick with opening a new tab every time I disconnect, to reset the title?

share|improve this question
up vote 7 down vote accepted

Add a PROMPT_COMMAND to your .bash_profile

export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}\007"'

The PROMPT_COMMAND gets executed every time the prompt is displayed.

share|improve this answer
Just the ticket, thanks. – Peter O'Callaghan Apr 16 '13 at 12:09
Be sure to add your code to PROMPT_COMMAND rather than replacing it, e.g., PROMPT_COMMAND="<your code>; $PROMPT_COMMAND"; otherwise, you’ll disable other functionality that uses this variable. For example, /etc/bashrc uses it to set the terminal’s current working directory so Terminal can display it and use it for various operations. – Chris Page Oct 25 '14 at 0:06
@ChrisPage Does the new code need to come before $PROMPT_COMMAND for the other functionality to be preserved? – reve_etrange Oct 25 '15 at 3:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.