Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.5: Show remote host names as tab titles in Terminal Apps
I have about a half dozen hosts that I ssh to on a regular basis. I often end up with multiple tabs, and it's very helpful if the tab label indicates what machine I'm connected to. Using iTerm's bookmarks, this works as desired with the bookmark name showing up as the tab name.

It took me a while, but I figured out a way to achieve the same result using the updated Terminal program that ships with Leopard. With the new Terminal, it's straightforward to save connections that automatically ssh to the desired host, and also display the remote system's name as the window title. Unfortunately, there's no obvious way to override the tab label, which displays the shell name.

My solution is kind of crude, but it does work. Simply create a hard link to the ssh binary with the name of each remote system you need to connect to (symbolic links don't work; ssh is still displayed):
sudo ln /usr/bin/ssh /usr/bin/remote-name
Then, while running Terminal, copy one of the existing terminal templates and modify it as you normally would to change colors, etc. After that, in the shell settings tab, substitute the remote-name link you've previously created for ssh; an example makes this more clear.

Instead of ssh -l username remote-name, specify remote-name -l username remote-name, and voila, the remote system name is now displayed in the tab label.

[robg adds: This worked for me, and could be extended to other commands. Hopefully a future Terminal update will allow easier custom tab titles.]
    •    
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[30,196 views]  

10.5: Show remote host names as tab titles in Terminal | 11 comments | Create New Account
Click here to return to the '10.5: Show remote host names as tab titles in Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Show remote host names as tab titles in Terminal
Authored by: wgscott on Nov 12, '07 07:53:05AM
One thing to be cautious about is how hard links behave on the HFS+ file system: It would be good if Terminal adopted iTerm's use of the standard xterm title for the title bar and the standard xterm iconified label for the tab. iTerm still works great by the way, and the tabs and title bar are both completely customizable.

[ Reply to This | # ]
10.5: Show remote host names as tab titles in Terminal
Authored by: einsturz on Nov 12, '07 08:50:29AM
Actually, Terminal accepts the old xterm escape codes for updating a title bar. Here's some good info on it:

http://www.trilug.org/~chilcote/Unix/titlebar.html

Basically, doing something like this:

echo "<ctrl-v><esc>]1;$(hostname)<ctrl-esc><ctrl-g>"

Will put the current hostname in the title bar. You could create some aliases to manipulate that before and after ssh is called.

[ Reply to This | # ]
10.5: Show remote host names as tab titles in Terminal
Authored by: einsturz on Nov 12, '07 08:53:06AM

Oh, scratch that. I just realized it updates the window title but not the tab titles.



[ Reply to This | # ]
10.5: Show remote host names as tab titles in Terminal
Authored by: brainsik on Dec 22, '07 09:44:41AM

You might be interested in these instructions on how to make Terminal automatically set the tab title to the current working directory. A bit dirty, but it gets the job done.

Personally, I need the tab title to tell me what remote machine it's logged into. That's the bulk of my usage. I'll see what I can do.



[ Reply to This | # ]
10.5: Show remote host names as tab titles in Terminal
Authored by: EricAnderson on Mar 02, '08 12:31:46PM

I've written a SIMBL plugin to take care of this. Its only Alpha but you should check it out.

Terminal.app Tab Namer

[ Reply to This | # ]
10.5: Show remote host names as tab titles in Terminal
Authored by: amylinari on Jun 09, '08 03:47:53PM
I've just posted an alpha release of a perl wrapper for command line utilities which can flexibly set tab titles when invoking specific commands, switch windows settings and more. For those with a basic knowledge of the command line, it should be straightforward to use. It should work on all recent versions of OS X, any platform.

An installer is available at:
http://purpleamy.com/magicwrapper/

[ Reply to This | # ]
10.5: Show remote host names as tab titles in Terminal
Authored by: nicolas.cros on Sep 26, '08 06:53:12AM
http://purpleamy.com/magicwrap/ is a really nice utility !
Many thanks !

---
Did you ever visit "The Cobbler's House" ? see http://barsa.free.fr

[ Reply to This | # ]

Solved in 10.6: no need for workarounds
Authored by: some0ne on Sep 08, '09 12:50:00PM
This has been finally fixed in 10.6. It took Apple only a few years. The tab title is now set to whatever you set the PROMPT_COMMAND environment variable. This is what I use in .bashrc to set the tab title to :

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


[ Reply to This | # ]
Solved in 10.6: no need for workarounds
Authored by: krpan on Nov 12, '09 11:32:34AM
To be precise it is the command:

/bin/echo -ne "\033]0;WHATEVER_YOU_WANT_IN_YOUR_TAB_TITLE\007"

that sets the tab title! Of course you should replace WHATEVER_YOU_WANT_IN_YOUR_TAB_TITLE with what you actually want displayed in the title. The above command can then be used in places like PROMPT_COMMAND environment variable under bash or alias 'precmd' under tcsh, etc.

Another important note, if you do not have GNU echo (and OS X does not!) you must replace the above command with:

echo -n "^[]0;WHATEVER_YOU_WANT_IN_YOUR_TAB_TITLE^G"

where ^[ and ^G are actual control characters for ESCAPE and BEL respectively.

[ Reply to This | # ]

since 1981...(X10 - preX11 days)
Authored by: slashlos on Jun 14, '10 01:56:25PM

Well, since the X10 and the early 80's I wrote this. Works just about every where http://public.me.com/slashlos; follow path to unix tools.

Therein is the ^G sequence to set the tab title.
--
/los



[ Reply to This | # ]
10.5: Show remote host names as tab titles in Terminal
Authored by: xenofan on Nov 23, '10 10:20:30AM

Additionally, if you would only like the current directory to show up in the title of the current tab, add the the following to your .profile file:

PROMPT_COMMAND='echo -ne "\033]0;${PWD##/*/}\007"'



[ Reply to This | # ]