Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Starting on OS X, I ssh into foo (a Linux box). My terminal title changes to foo. I then ssh into bar (another Linux box). My terminal title changes to bar. I log out of bar. My terminal title changes to foo. I log out of foo. My terminal title stays foo (rather than changing back to the original title). The problem is obviously not with the terminal, since it works correctly when logging out of a Linux box back to a Linux box. It probably isn't ssh as I have the same problem with vim. In my mind that leaves the shell. I am using BASH. Looking through the environment I don't see a lot of difference between the Linux box and my OS X box. Both are using a TERM of xterm.

share|improve this question
add comment

1 Answer

up vote 12 down vote accepted

Adding

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

to my .bash_profile fixed the problem.

It appears as if the string in PROMPT_COMMAND gets executed every time the prompt is displayed. From the man page:

PROMPT_COMMAND

If set, the value is executed as a command prior to issuing each primary prompt.

share|improve this answer
3  
You're unlikely to log into OS X via the console, but it might happen. To prevent problems in that event, I wrap this whole thing in a case "$TERM" in xterm*|rxvt*) type of deal. I think I originally got the idea from here: tldp.org/HOWTO/Bash-Prompt-HOWTO/… –  Telemachus Aug 24 '09 at 19:03
    
Oh, also, I find it better to go into Terminal.app's preferences (Preferences -> Settings -> Window) and remove everything that it tries to add to the title-bar, but ymmv. –  Telemachus Aug 24 '09 at 19:05
    
Well, I use iTerm.app not Terminal.app, and it is working. You do have a point about the real terminal. My Linux box has just such a check, so I will add it to my profile, thanks. –  Chas. Owens Aug 24 '09 at 19:55
add comment

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.