Set Terminal tab name automatically?
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.
You can set the window title from the login script of your shell, by including the echo
you run manually.