SSH Hostnames in Terminal Tabs

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

  1. A4orce84 macrumors 6502

    Joined:
    Apr 17, 2012
    #1
    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:
    [​IMG]

    OSX Terminal:
    [​IMG]

    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:
    http://www.cnet.com/news/how-to-use-ssh-host-names-for-tabs-in-the-os-x-terminal/

    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!

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

    mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #2
    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:

    Code:
    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

    Joined:
    Apr 17, 2012
    #3
    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,
    Asif
     
  4. NoBoMac macrumors 6502a

    Joined:
    Jul 1, 2014
    #4
    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

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

Share This Page