1

I can set the tab name using ⌘ I or echo -en "\033]1; NAME \007"

What I would like to do is set this automatically when I ssh into a remote system rather than the user@hostname I normally get.

I have searched terminal & ssh documentation but not found any workable solution.

I can change tab name in a script but it is always overwritten by ssh.

After connecting I can again set tab name, but I would like to automate this.


The supposed duplicate seems to be about setting AFTER ssh exits; I want during ssh and often have ~6 ssh sessions open.
I have tried export PROMPT_COMMAND="echo -ne '\033]0;NAME\007';$PROMPT_COMMAND" before ssh but this seems to have no effect and of course running after connect doesn't either.

There is nothing in my Linux .profile which sets this.


NOTE the title is set to user@hostname even if I use ssh user@IPaddress so this is almost certainly coming from the ssh server, but this does not seem to be documented.


Profiles/Window/Title is set to "Term" which is overwritten (with user@hostname ~ - the Linux prompt) when ssh connects.
Profiles/Window/Tab is empty (although I have experimented with settings to no effect)

The only way I have found to change after connection in to use ⌘ I then manually set the Tab title. If I could automate this it would be a viable solution.

PROMPT_COMMAND on the server is empty (unless I set as suggested when it shows "true").


I tried ssh -t -t -t hostname "echo -en \"\033]1; Pi3+ \007\"; exec /bin/bash --noprofile --norc" as suggested by jaume, which DID successfully set Tab name.

Unfortunately none of my aliases etc work so this is not a workable solution, but maybe with further work it will. This also sets Terminal Window title to user@hostname ~, but frankly I don't care what the Window says.

12
  • 1
    Check the shell profile of the remote shell. Something in there may set the title.
    – nohillside
    Commented Oct 20 at 5:20
  • If you set the Terminal name while the ssh session is active (with the echo command, running in the shell), does it change?
    – nohillside
    Commented Oct 20 at 7:21
  • Also, as written it's unclear when you want to set the title (or when it doesn't work): Does it not work while you are logged in remotely, or does it not set the title back once your ssh session terminates?
    – nohillside
    Commented Oct 20 at 7:43
  • 2
    The ssh server doesn't change window titles, the shell you are running via ssh may. But can you help me to understand what "It is simple to set terminal title but as in the question it is overridden by the ssh session" means? If you log in via ssh and then run echo -en "\033]1; NAME \007", does NAME stick or does it get overwritten?
    – nohillside
    Commented Oct 20 at 8:20
  • 1
    The ssh session doesn't override the tab title, but the shell on the remote system (usually because the shell startup scripts set the PROMPT_COMMAND environment variable). To prevent this from happening, you can force ssh to run a session that selectively sets PROMPT_COMMAND. For bash, can you try the following command (it should set the tab title to "IT WORKED", ): ssh -t -t -t hostname 'exec /bin/bash --noprofile --rcfile <(cat ~/.bashrc; echo "export PROMPT_COMMAND=\"true\""; echo "echo -ne \"\033]0;IT WORKED\007\"")' (replace hostname as necessary) and report back?
    – jaume
    Commented Oct 20 at 8:56

0

You must log in to answer this question.

Browse other questions tagged .