Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Bug in terminal. Wrong host name displayed in title bar in some cases.

Steps to repoduce.

1) open terminal.

2) ssh into host A

3) exit host A

4) ssh into host B

5) exit host B

6) ssh back to host A

7) vi a file (e.g. vi touchfile)

8) Note that title bar of the terminal window shows host B, when in fact you are editing a file on host A.

9) quit vi note the title bar changes back to the correct host.

Terminal -OTHER, OS X Mountain Lion (10.8.2)

Posted on Oct 4, 2012 7:14 AM

Reply
9 replies

Oct 5, 2012 5:58 AM in response to msloan1

Terminal does not really know you are logging into a remote system. If anything, something on the remote system is sending escape codes that change the Terminals title bar. Vim (what is really invoked by vi) will send those escape codes.


echo -e "\e]0;`hostname`\007"


If you put something like this in your remote hosts shell initialization file, it will always set your title bar to the host you are ssh'ing into. Depending on the shell you us on those remote systems, you may need to use different syntax for the echo command. What I have shown is for 'bash'

Oct 5, 2012 9:33 AM in response to msloan1

What do you have set for Terminal > Preferences > Settings > Window > Title ?


Are you, or any of your login shells on any of those machines, emitting any escape codes?


I don't see any built-in settings to do this. You must be relying on some of those escape sequences. That is a popular trick using bash preexec commands, but not reliable.

Nov 27, 2012 1:10 PM in response to msloan1

I just got my new MBP (10.8) and after setting everything up I experience the same problem even faster.


1. open terminal ( title = bash )

2. ssh with username@host ( title = username@host: )

3. quit ssh session ( title = username@host: )


The title stays like this until I ssh to another host and then changes to the new username@host.

This only happens on my new 10.8 MBP and but not on my other 10.5 MBP. Not sure if it's the terminal.app or the OS itself ... but still annoying 🙂

Nov 27, 2012 4:56 PM in response to Lowry76

See my earlier response: <https://discussions.apple.com/thread/4394262?answerId=19902085022#19902085022> in this thread.


Terminal does not know you ssh'ed and it does not know that you exit'ed from the ssh session. So the Terminal cannot know to change your title.


If this worked on another system, then it was the 'bash' shell doing this, or the old ssh as it was exiting from the session reset the title.


As far as I can see, those are the only to possible ways the title could have been reset to 'bash' after the ssh session terminated.


If you wish to control your title, you can modify your 'bash' PS1 prompt to include an escape sequence.


Starting with.bash_profile (create it if it does not exist, unless you have a .profile, then use that instead), you will need to create your own PS1 variable


PS1="\[\e]0;bash\007\]$PS1"


The \e]0;bash\007 will tell the Terminal to set 'bash' as your title every time bash issues a prompt. So when you return from your ssh session, you will get a bash prompt and it will reset your Terminal title.


The \[...\] tells bash that the stuff in between is not displayed in the prompt, so command line editing is done correctly when lines are longer than the width of the terminal.


the $PS1 just appends your current prompt to the end of the escape sequence that changes your title.


You can replace 'bash' in the title escape string with anything you like. For example you could put \u@\h there to substitute your username@hostname for your local system:


PS1="\[\e]0;\u@\h\007\]$PS1"

Nov 28, 2012 12:58 AM in response to msloan1

Thank you for the answer and the work-around.

I agree that it's most likely not the Terminal.app but because there was a thread already I didn't want to open a new one. Maybe I should have made a new one "Bug in XCode/shell/ssh" because (at least from my point of view) this is a bug and not a feature. None of the linux derivates I used in the last years showed a similar behavior (not even cygwin consoles). Either the console title should stay as is whatever session you open or, in case it changes the title, it should change it back when the session is closed. But changing it only when a session is opened? ...


Anyways, maybe someone will realize and change it in the next version of whatever script is responsible for this 🙂

Nov 28, 2012 4:11 AM in response to Lowry76

In general it is better to open your own thread, as you then get to control the discussion and award credit for answers you like.


There is one other possibility. The remote system issued the title escape sequence in the /etc/profile or similar system wide shell initialization script.


And of course your own remote shell initialization script could have issued the title escape sequence, especially if the first copy is provided by your local UT group and you did not suspect it existed.

Bug in terminal. Wrong host name displayed in title bar in some cases.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.