I would like to know how can I set the shell title to the name of host we are currently logged into. My scenario is like this. I log into host A then open up screen and create several new windows and ssh to different hosts on those windows. So I would like screen title at the bottom to show the current host it is in. im talking about this particular string at the bottom

  • I'm using terminator – Sanjan Dec 1 '17 at 4:45

One way to do this is to use the LocalCommand feature of ssh. With this method, an escape sequence to change the terminal's title will be printed after a successful connection to a remote host.

Edit or create ~/.ssh/config to include something like:

Host *
    PermitLocalCommand yes
    LocalCommand printf '\033]0;%%s\007' '%h'

The downside of this method is that the title remains changed after logging out of the remote server. You can get around that with:

printf '\033]0;%s\007' "$(uname -n)"

If you want to automate this, you could use a function:

lssh () {
    /path/to/ssh "$@"
    printf '\033]0;%s\007' "$(uname -n)"

This answer assumes that your terminal emulator uses the same escape sequences as XTerm. If this is not the case, you should check the documentation for your specific terminal emulator.

One caveat in the case of GNU screen is that a single terminal window may contain several virtual windows. In that case, you could use a different escape sequence (\033k%s\033\\) to set the internal title of a single virtual window.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.