Terminal.app and Window Names

pudge on 2003-11-19T03:02:27

Right now, the name of my frontmost window in Terminal.app is "pudge@slashdot-nfs-1:/usr/local/src — ssh". How does Terminal.app know I am logged into that machine, and am in that directory? I do know "pudge@slashdot-nfs-1:/usr/local/src" is called the "custom title" portion of the name, but I do not know how it is being set automatically.


Xterm?

kasei on 2003-11-19T04:51:44

I believe (and may be way off on this) that it's a feature of the xterm protocol. If not, I too would love to know how this occurs.

Play with this:

Robrt on 2003-11-19T06:08:37

if [ ${TERM} = "xterm" ]; then
    /usr/bin/printf "\033]1;$* \007"
    /usr/bin/printf "\033]2;$* \007"
fi

(but, your shell is probably doing this already, possibly in a pre-command hook.)

Re:Play with this:

pudge on 2003-11-19T06:45:57

Aha! It was doing:
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/user/}\007"'
Neat little trick. Thanks, that rules.

Re:Play with this:

blech on 2003-11-19T12:56:17

Yes, the Terminal in Panther uses xterm title escapes. I noticed it a few weeks ago while a friend was logged into a work machine (which all have the appropriate trickery in a bash config file somewhere), and was wondering how long it would take for folks to notice it.

I'm not sure if you can override it using the Terminal window inspector to set a custom title, as I don't have Panther yet. I'd hope so. (Otherwise, I suppose you could edit the config files wherever you needed to, but that's a bit tedious.)

GUI settings.

Louis_Wu on 2003-11-19T20:10:38

There is also an easy GUI way of changing the Terminal title bar.

  1. Go to Window Settings... in the Terminal menu, it's right below Preferences.
  2. Pick the Window item in the menu at the top of the Terminal Inspector window which appears.
  3. Play with the nifty options.

I have it set to display the active process name, the window size (104x57 characters is half of my screen, and is a handy size for reading man pages), and the shortcut command key for that window. You can also enable the tty name, the .term startup script used, and the shell command name (which I imagine would be handy if you use different shells, bash & tcsh for example).