0

If I connect to one of my Pi using ssh ssh [email protected]

This sets the macOS terminal tab title to "pi@MilliwaysPi4"

If I connect to one of my Macs using ssh ssh [email protected]
The macOS terminal tab title remains at its default.

I can then manually set using the following:-
echo -en "\033]1; $(hostname) \007"

This sets the macOS terminal tab title to "Zaphod.local"

Is there any way to get macOS to automatically set the title?
Is there a ssh setting which would facilitate this behaviour?


I have tried many options;
Including echo -en "\033]1; $(hostname) \007" after ssh does not work, as any subsequent commands do not run on the host.

Including echo -en "\033]1; $(hostname) \007" before ssh sets the Title to the host on the host.

I could hard code the Title into a script before ssh which does work, but often I use IP Address rather than a HOSTNAME so this is not generic.

Apparently something happens when sshing to Linux which sets the title, but not when sshing to macOS. Ideally I would like to discover what this is.


The Linux .bashrc contains

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)

although frankly this is inscrutable.

5
  • "... after ssh does not work, as any subsequent commands do not run on the host." doesn't make sense because the echo goes to Terminal so it doesn't matter on which host it runs. But check the shell init files on your Pi, whatever is done there to set the title will also work on your Mac.
    – nohillside
    Commented Jul 15, 2021 at 6:29
  • @nohillside I tried, and it does nothing. The echo may work (but doesn't seem to). In any event the hostname needs to come from the target. ~/.bash_profile contains export PS1="\h:\[\033[0;30;33m\]\w\[\e[0m\]$ " (which affects the prompt) but I am at a loss to find anything which would set title (but will continue looking)
    – Milliways
    Commented Jul 15, 2021 at 6:46
  • Maybe I don't understand the problem then: If you ssh into your Mac and run echo -en "\033]1; $(hostname) \007" once logged in, does the title change?
    – nohillside
    Commented Jul 15, 2021 at 7:52
  • @nohillside Yes, this works . I wrote "I can manually set using the following:- echo …" but maybe this is not clear to others. I will try putting into ~/.bash_profile.
    – Milliways
    Commented Jul 15, 2021 at 8:01
  • If it works manually it also works in bash_profile.
    – nohillside
    Commented Jul 15, 2021 at 11:11

1 Answer 1

1

You can set the window title from the login script of your shell, by including the echo you run manually.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .