Nice titles in screen

posted on 12:12 PM on Sunday 21 May 2023

I use GNU screen a lot since I work on remote servers via SSH. I realised that on RedHat system, the title of the windows have very useful information like the username, host and path. In Ubuntu, there is nothing but just the shell name like bash. Took a lot of searching but the fix is actually quite simple. Just configure the PROMPT_COMMAND variable which is a command that is executed when the prompt is changed.

Add the following to you .bashrc file:

# add the nice titles in screen
if [ "$PS1" ]; then
  case $TERM in
    PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'

The PS1 check ensures that this is an interactive shell and there is a case to see if the term is screen and if so, it will add the PROMPT_COMMAND.