2

When I am SSH'ed into any one of my Linux devices, the title bar on Terminator displays user@hostname, where hostname is the computer I am SSHing from, rather than the computer I am SSH'ed into (i.e. the title bar mirrors $PS1 from the local device rather than the remote device). This makes it very confusing if I am SSH'ed into all 4 computers at the same time and can't see their prompts (as all their title bars are identical!).

How can I have Terminator display the correct hostname?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Sophie
  • 755
  • 3
  • 10
  • 26
  • `printf "\033];%s\07\n" "${USER}@$(hostname)"` maybe ? – MelBurslan Mar 11 '16 at 18:40
  • what distro are you using on that computers? All my computers I ssh to do that with default configuration and I don't think it is needed to create such wild stuff as described in the answer. – Jakuje Mar 11 '16 at 19:31
  • Chromixium (which is based on Ubuntu) on 3 of them, Peppermint Linux 6 on the other one. – Sophie Mar 11 '16 at 19:38

1 Answers1

3

While it's certainly possible for users to customize their prompt (and make that update the terminal's title), most use the default shell behavior.

It sounds as if your local machine is setting the title string as a side effect of your prompt, and that the remote machines are not changing the title.

Given that, you can update the title without interference by the remote machines, e.g., using a wrapper script for ssh such as this:

#!/bin/bash
# trim parameters, leaving just the last (user@hostname or just hostname)
title=$(echo "$*" | sed -e 's/^.* //')
printf '\033]0;%s\007' "$title"
/usr/bin/ssh "$@"

and putting that in your executable path ahead of /usr/bin, you could call that "ssh" and have it set your title string as you visit each remote machine. After exiting ssh, your local prompt would reset the title string back to the local machine.

In a followup comment, OP indicated that the connections are made to an IP-address. If the remote machine has a hostname, then it would make the procedure clearer to use that, or (if not in DNS) collect the hostnames into the local machine's /etc/hosts. Ultimately, DNS is the way to go...

For reference:

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268
  • Maybe I did this wrong, because although it works, it sets the title to whatever comes after the ssh command. For instance, the title when logged into my one machine now says "-p 22223 192.168.1.11" rather than "user@hostname". Although that is an improvement, it's not the expected behavior. – Sophie Mar 11 '16 at 19:49
  • Sorry - I was making a simple script, assuming the case where one does `ssh hostname` or `ssh user@hostname`. For your case, I'd have an `/etc/hosts` file so I could refer to everything by name, and amend the script to ignore options/values such as the `-p22223`. – Thomas Dickey Mar 11 '16 at 19:51
  • Ah, I forgot about /etc/hosts. Adding my machines to that did the trick. – Sophie Mar 11 '16 at 20:23
  • And if I wanted to display user@host $pwd, how can I do that? I tried adding `"$pwd"` after `"$title"`, but that just replaces `$title`. – Sophie Mar 11 '16 at 21:12
  • If you want the working directory on the *remote* machine to show in the title, you'll have to configure the `PS1` string on the remote machines. The Batch Prompt HOWTO is a good place to start. – Thomas Dickey Mar 11 '16 at 21:18
  • Thanks Thomas. For more than one param $@ should be used without the quotes. It might be required to quote each param if it contains spaces or other special characters – ozma Dec 07 '17 at 10:00
  • The **`$@`** always works properly when quoted. – Thomas Dickey Dec 07 '17 at 10:09