SSH Hostnames in Terminal Tabs

Discussion in 'OS X Mavericks (10.9)' started by A4orce84, Aug 15, 2014.

  1. A4orce84 macrumors 6502

    Apr 17, 2012
    Hey Everyone,

    I've been trying to figure out how to get the hostnames of servers I ssh into as titles on my Terminal Tabs like Linux does:

    Linux Terminal:

    OSX Terminal:

    As you can see having tabs that say "ssh" isn't really useful when I have multiple tabs open with ssh connections in each one. I've found the following instructions online on how to update this automagically here:

    But it doesn't seem to be working in mavericks correctly. Has anyone gotten this working? Ideally, I just want to SSH into any server, and automagically have the title update to user@host in my title bar.

    Any help would be greatly appreciated, thanks guys!

  2. mfram, Aug 15, 2014
    Last edited: Aug 15, 2014

    mfram macrumors 65816

    Jan 23, 2010
    San Diego, CA USA
    My tabs are getting the username and server name in them when I ssh to my Linux box. I didn't do anything special to set that up. It just seems to be happening. It's a little annoying because when I disconnect the tab title does not clear. It stays as 'uuuuu@host:~'

    This implies to me that the tab name is getting set from the shell on the remote host, not the local one. My guess would be that the 'set status string' control sequence must be getting sent from the remote host. Maybe from SSH or bash on the remote host. Not sure which.

    Quick edit... I found something which may be contributing. On my Linux box, I noticed the following env variable in bash:

    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
    Yep, just confirmed this on my Terminal window. When I exported the PROMPT_COMMAND variable on the Mac bash, it started updating the tab with the information. So it appears you should set that env variable on the host you are connecting to. Edit as you see fit.

    Also, that variable is a feature of bash. So if you aren't using bash on the remote machine, it's not going to work unless there are similar features in other shells. Read man pages as appropriate.
  3. A4orce84, Aug 16, 2014
    Last edited: Aug 16, 2014

    A4orce84 thread starter macrumors 6502

    Apr 17, 2012
    Thanks mfram! That was EXACTLY what I needed. I exported that command to my "remote" .bash_profile, so now the specific boxes I ssh into, my tabs update auto-magically. THANK YOU SIR!!!!!!!! =)

    Follow-up Question: If you find out a way to clear the tabs (when I exit back into my local Mac), please let me know.

    Thanks again,
  4. NoBoMac macrumors 68000

    Jul 1, 2014
    echo -ne "\033]0;\007" will clear the title banner.

    Make an alias for it, or, .bash_logout file.
  5. A4orce84 thread starter macrumors 6502

    Apr 17, 2012
    You create the .bash_logout script on the remote server? Or on your macbook (locally)?

Share This Page