Reputation: 5119
I know how to list out the available windows in Screen using C-a "
and/or C-a '
, but how do you specify that you want to go to the very last screen without having to explicitly say so.
Like what I'm looking for is something like this:
C-a L
NOTE: I'm just asking whether screen supports this natively or if I'll have to write a bit of script in order to get this to work, also, tips and pointers for writing said script, if proved necessary, would be appreciated.
Upvotes: 0
Views: 973
Reputation: 3249
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.
Upvotes: 0
Reputation: 263307
Assuming you have a window 0 (i.e., you haven't closed it), you can do
C-a 0
(select 0
) followed by
C-a <backspace>
(prev
), which switches to the previous window; if you're on the first window, it wraps around to the last.
The prev
command has several other default key bindings:
C-a h
C-a p
C-a C-p
Upvotes: 2