Search code examples
gnu-screen

How to set window title in the GNU screen to a hostname of current machine?


There is a documentation about setting window title: https://www.gnu.org/software/screen/manual/html_node/Naming-Windows.html

I don't want to change .bashrc on all machines to make dynamic screen. However it will be good set hotkey in my .screenrc to set title using :title (C-a A) command with proper argument.

Maybe there is a solution to provide an output from uname -n to :titile command. Or something similar which automatically or semi-automatically sets window title to hostname.

Questions are:

  • is there a way to provide output of uname -n to :title command?
  • is there any other way to set window title to current hostname without changing .bashrc?

Solution

  • There are two approaches to solve it:

    1. Print out sequence which gnu screen can parse for window titile ESC k my-titile ESC \. Screen will extract my-title. It can be done via:
    printf '\ek%s\e\\' $(uname -n);
    
    1. Run screen -X title my-titile to set a titile of current window.

    Since I want to do it for all hosts which I sshed into, there is a trick to wrap actual ssh command into ssh() function using one of aforementioned approaches.

    E.g.:

    ssh() { printf '\ek%s\e\\' "$1"; command ssh "$@"; }
    

    Thanks to #screen on freenode : )

    ref.: https://www.gnu.org/software/screen/manual/html_node/Dynamic-Titles.html#Dynamic-Titles