1

I have a problem with the window title in the Terminal window on OS X:

  1. Start Terminal. Window title is "bash"
  2. Type "ssh external" to connect to an external server. Window title is "user@external:~"
  3. Type "exit". I am now back at my local machine, but the window title still says "user@external:~".

How do I make the window title return to "bash", which I assume would be correct since I have logged out of the external server and returned to my local machine?

My ~/.bash_profile has the same PS1 value:

export PS1='\w$ '

2 Answers 2

0

You define the title by echoing a specially formulated string to your terminal.

You could define:

function update_title {
   echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007" ;
}

and then use:

update_title

each time you want to update it.

If you want it updated "all the time", you could use your shell's support for "just-before-displaying the prompt" functions. ex, in (a decently recent) bash:

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

But I find this a bit overkill : it re sets the title before every prompt, not just when needed...

3
  • So you could say the reason this happens is that the prompt is set at login, but not at logout?
    – forthrin
    Nov 26, 2012 at 14:50
  • not exactly, but in your case it seems so. Nov 26, 2012 at 15:06
  • You may have it set in your login scripts? (difficult to say what exactly happen, could be set in a variety of places) Nov 26, 2012 at 15:07
0

Here's a function that sets the title any string you give it, or hostname and current directory if you don't provide a title. I call it "xst" for "xterm set title".

xst () 
{ 
    if [ $# -eq 0 ]; then
        echo -e "\x1b]0;${HOSTNAME}:${PWD}\x07";
    else
        echo -e "\x1b]0;$*\x07";
    fi
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .