7

I use one of the many solutions to set the terminal title:

Function in .bashrc:

function set-title() {
  if [[ -z "$ORIG" ]]; then
    ORIG=$PS1
  fi
  TITLE="\[\e]2;$*\a\]"
  PS1=${ORIG}${TITLE}
}

And it works perfectly! But when I ssh to a remote host, the title is changed to ubuntu@remote.host.name.

Is there any solution to prevent title changing after ssh?

i.bondarenko
  • 171
  • 3
  • 1
    You probably need to put this in your remote machine's .bashrc as well.@i.bondarenko – Pie Oct 01 '19 at 04:06
  • 1
    Unfortunately I can't modify the remote machine's .bashrc. Some of them in production environment so any modification on them is restricted. Others are test servers and their uptime very short so I need to modify .bashrc many times per day. But anyway thank you for the suggestion @Pie. – i.bondarenko Oct 01 '19 at 04:34
  • 1
    I tried to combine "ssh + set_title_command" and wrapp it into alias, but without success. – i.bondarenko Oct 01 '19 at 04:40
  • Combine how? I'd use alias myssh="ssh servername;set_title" – waltinator Dec 04 '19 at 18:16
  • @waltinator Thank you for the suggestion. I have tried: alias myssh="ssh ubuntu@host;set-title my_title1" but without success. – i.bondarenko Dec 05 '19 at 06:54
  • Aliases won't work as they will still run on the client, not the remote machine. And set-title will only be invoked after ssh ends, i.e., when you disconnect from the remote. – MestreLion Nov 26 '21 at 16:17
  • Try this: https://askubuntu.com/questions/1470061/change-title-for-tabs-in-terminator/1473378#1473378 – tquang Jun 20 '23 at 03:03

1 Answers1

2

If you cannot modify ~/.bashrc I assume you also cannot create or copy any file to the remote user's ~, right? Because if you can, then just add a ~/.bash_aliases that reverts the title to default: echo -ne '\e]2;\a'

So... your best bet is to trick the remote ~/.bashrc by setting a TERM other than xterm*|rxvt*, for example:

$ TERM=gnome-256color ssh ubuntu@remote.host.name

(IMHO, that's a pretty stupid restriction/policy. ~/.bashrc is a file that only runs on interactive sessions, so it won't affect any script or service. And the default .bashrc that ships by default in Ubuntu and other distros have this idiotic behavior of setting the title, it could/should be patched by devs/sysadmins when setting up their servers)

MestreLion
  • 20,086