Dominic Cleal's Blog

Fri, 02 Sep 2011 22:28:58 BST

permalink Renaming GNU Screen windows by SSH remote hostname

I use screen heavily at work, usually with a dozen SSH sessions open at once across different servers. The following tip's handy for me as it renames your window's title to the remote hostname. Combined with a hardstatus "tab-bar", it makes finding open sessions easier.

Create ~/.ssh_hostname and chmod +x:

echo -ne "\033k$1\033\\"

And then add to ~/.ssh/config (if you have Host sections, put it above them):

PermitLocalCommand yes
LocalCommand ~/.ssh_hostname %h

You can also do this via a function in your shell profile, though that has the disadvantage that you have to parse SSH arguments, or assume the last is always the hostname. Similarly, you can add the magic echo statement into the remote shell profile (or your remote shell prompt) on every machine/account.


Comments for this entry are now closed.