Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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

1 Answer 1

up vote 3 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. –  Cags 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 at 0:06

Your Answer

 
discard

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.