Gnu screen, how to update dynamically the title of a window?

Solution 1:

In your .bashrc file set your PROMPT_COMMAND like this:

UPDATE:

case "$TERM" in
    screen*) PROMPT_COMMAND='echo -ne "\033k\033\0134"'
esac

UPDATE: seems to be a bug with echo built into bash. Solution should be either use of /bin/echo or \0134. Try:

$ echo -e "\134 = \0134"
\134 = \
$ /bin/echo -e "\134 = \0134"
\ = \

This is the escape sequence that screen needs to identify which command is being run, and replace the title of your current window.

Then, on your .screenrc file, make sure the following lines exist:

shelltitle '> |something:'
hardstatus alwayslastline

The pattern search|name tells screen to search your end-of-prompt for some string (in this case, '> '). The name part, specifies the default shell name for the window. So, when you have nothing but the shell running, you'll see something like:

$ something:

But when you run top:

$ something:top

Solution 2:

As an alternative, you could use tmux instead of screen. Tmux will automatically set the current window's title.