SSH Terminal Window Manager Window Title – How to Fix Terminal Title After SSH Remote Logging

sshterminalwindow titlewindow-manager

right now I am using an one-line perl code to change titles of my terminal bars,

print("\e]0;@ARGV\7");

but every time after I ssh to another remote machine, the title will be modified by the host (by which I'm not particularly bothered). But after I exit from the connection, the modified title remains. Is there a way to fix this? essentially I want a fixed title for my terminals when operating locally.

I primarily use xfce terminal and terminator under either CentOS or Debian. Thanks.

EDIT

Another subtlety is that, rather having all terminals the same name, I would prefer to have the freedom to edit their titles on-the-fly but only forbid SSH session from modifying what I edited.

Best Answer

I don't know about window titles, but I have been trying to have my system do something on terminating a ssh session—actually, after terminating a ssh session. In short: it doesn't work like that. Basically you have three choices:

  1. Write a wrapper around ssh, i.e., an executable shell script named ssh that takes precedence over /usr/bin/ssh in your $PATH which contains the line exec /usr/bin/ssh $@ somewhere in its middle. This enables you to have your shell do some stuff before and after the effective ssh binary is run, while keeping th eoverhead to a minimum.

  2. Write a patch against the SSH sources of your choice to provide you a cleanup hook that executes a shell command passed via commandline or some config-setting. That's what we want.

  3. Have PROMPT_COMMAND evaluate the output of history. Basically a more generic and more ugly approach to 1.

Related Question