If you create a new windows with Ctrl+a c
screen switches to the newly created last window. (If that isn't what you were looking for then:
screen -Q select $(screen -S $STY -Q windows|sed 's/ \([[:digit:]]*-*\**\)\$/\n\1/g'|tail -n1|cut -d: -f1|sed 's/[^[:digit:]]//g')
will "Switch to last window in GNU Screen" from within any screen window.)
Alternatively (without depending on $STY, and presuming that you want the first or only screen session in screen -ls
) you can use:
screen -S $(screen -ls|grep '^\s'|awk '{print $1}'|head -n1) -Q select $(screen -Q windows|sed 's/\([[:digit:]]*-*\**\)\$*\!*/\n\1/g'|grep '[[:digit:]]'|tail -n1|sed 's/[^[:digit:]]//g')
If this is something that you often need you can add:
_stslw_fn(){ screen -Q select $(screen -Q windows|sed 's/\([[:digit:]]*\)[^ ]*/\n\1/g'|tail -n1);};alias stslw="_stslw_fn"
to the end of ~/.bash_aliases
to create the stslw
(switch to screen's last window) command.