Is it possible to set the Screen Title using a shell script?
I thought about something like sending the key commands ctrl+A shift-
The following are other ways to script the renaming of screen titles:
Adding the following settings to .ssh/config
sets the screen title automatically upon logging in to a system using SSH:
Host *
PermitLocalCommand yes
LocalCommand [ "$TERM" == 'screen' ] && echo -ne "\033k%h\033\\"
Instead of %h
, which represents the hostname of the machine you are connecting with, you may use %n
, which is the actual name / alias you used to connect to the machine.
NOTE: You need OpenSSH >= v5.1 to be able to use the Localhost %n and %h parameters. Check out 'man ssh_config' for more info on LocalCommand.
To automatically revert the title, back to that of the hostname of the localhost, after closing the SSH session, you can add an escape sequence to you prompt variable PS1
in .bashrc
:
export PS1='you_favorite_PS1_here'
if [ "$TERM" == 'screen' ]; then
export PS1=${PS1}'\[\033k\h\033\\\]'
fi
These tricks are especially useful when using a .screenrc
config that shows you in what screen 'tab' you are currently working. Add something like the following to .screenrc
to get this working:
caption always "%{= kY}%-w%{= Yk}%n %t%{-}%+w%{ kG} %-= @%H - %LD %d %LM - %c"