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.

I use one Mac to do work on several others.

What I'd like to do is find a way to programmatically set the title of a Terminal.app tab to the name of the server I'm ssh-ed into, so I can determine at a glance which tab I want to jump to to check on a particular server.

Anyone know how to do this?

Thanks.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

Sure, this is an easy way to do it:

echo -n -e "\033]0;Superuser.com rules\007"

Just change "SuperUser.com rules" to whatever you would like to title the session.

To capture the host name and post it to the title you could run something like this

name=`hostname`;echo -n -e "\033]0;$name\007"
share|improve this answer
1  
Perfect. Just what I needed. –  alesplin Mar 2 '12 at 0:24
    
This is awesome and works great. Is there a way to make this happy automatically upon launching Terminal and/or changing hosts? –  Mitch Dec 15 '13 at 2:31

I wanted to do just this the other day and I came up with the following result:

put this in your .bash_profile / .bashrc file:

function tabname { printf "\e]1;$1\a"; }
function winname { printf "\e]2;$1\a"; }
function ssh() { echo "$@" | tabname `sed -E 's/(.*@)?([-a-zA-Z0-9\.]*)(.*)/\2/'`; /usr/bin/ssh "$@"; tabname; }

Automatically Changing Terminal.app Tab Names when using SSH

Hope this helps.

share|improve this answer
    
It uses a regular expression to pull out just the hostname. I'm only just learning regexes so anyone feel free to post a better solution if you can do it better. –  Ben Mackey Dec 24 '12 at 3:06

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.