Bash – Showing GNU screen session name and window title in shell prompt

bashgnu-screenprompt

Is there a way to present the GNU Screen session name and window title in the prompt of the shell (let us say, the Bash prompt defined by PS1)?

Best Answer

Screen supplies some environment variables (from screen(1) manpage):

STY              Alternate socket name.
WINDOW           Window number of a window (at creation time).

The "at creation time" means that if you renumber a window (using screen's number command), the shell will not be told about the change and $WINDOW will still be the same as the first window number.

You could use something like:

PS1='\u@\h(${STY}:${WINDOW}):\w$ '
Related Question