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.

Setting up a .ssh/config is a great time saver. The host aliases with user defined names make it easier keep track servers and key files. However, the OSX terminal tab names are displaying what ever the server says its host name is, instead of the host alias from the .ssh/config file.

For this entry:

Host CustName01
    HostName ec2-20-12-130-143.compute-1.amazonaws.com
    IdentityFile ~/.ssh/remote.pem
    User root

The OSX terminal tab name shows this:

root@domU-11-21-35-24-33-9A:~

I tried to solve the problem by setting the tab name before connecting:

Host *
    PermitLocalCommand yes

Host CustName01
    LocalCommand printf "\e]1;CustName01\a"
    HostName ec2-20-12-130-143.compute-1.amazonaws.com
    IdentityFile ~/.ssh/remote.pem
    User root

It sets the tab name before connecting, but then shows this again after connecting:

root@domU-11-21-35-24-33-9A:~

How can I get my tab to automatically show the CustName01 alias I specified in the ssh config file? Manually setting the value in the inspect tab dialog isn't what I'm after.

Executing the command to set the tab name while connected to a remote server does nothing:

printf "\e]1;CustName01\a"
share|improve this question
add comment

1 Answer 1

Kind of a hack, but this sort of works. I say sort of works because there are two places to set the title of the tab if you look in the tab inpector. I wasn't able to set the input I wanted that says "Tab Title" with applescript, but I was able to set the one that says "Window Title." This solution will help me know what machine I'm connected to though.

settabname.sh

#!/bin/bash

osascript -e 'delay 2' -e "tell application \"Terminal\" to tell window 1 to set custom title to \"$1\""

~/.ssh/config

Host *
    PermitLocalCommand yes

Host CustName01
    LocalCommand ~/.ssh/settabname.sh CustName01 &
    HostName ec2-20-12-130-143.compute-1.amazonaws.com
    IdentityFile ~/.ssh/remote.pem
    User root

The trick here is that & makes the bash with the embedded applescript execute asynchronously. The applescript has a delay which allows it to rename the tab after your remote connection does a rename.

Here's how you can clean up the tab name after the ssh command exits. http://unix.stackexchange.com/questions/40899/ssh-localcommand-on-exit

~/.bashrc

## run a cleanup command after ssh exit
ssh() {
    if command ssh "$@"; then
        # commands go here
        ~/.ssh/settabname.sh Local &
    fi
}
share|improve this answer
add comment

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.