I found in screen that I had problems creating a new window because by sending the "screen" command I was telling the most active screen to switch to that window.
So I found the "other" command to toggle back!
So if we want to add a shell to a screen session and not disturb any
open screen sessions, run:
#create the window and switch to it
$SCREEN -U -S $match -X "screen" -t $TITLE
#switch the window back
$SCREEN -U -S $match -X "other"
And then to create a new window, a shell, and attach to it, I use the
attached script.
I use this to spawn terminals which attach to my screen session:
gnome-terminal -e new-window
Here's new-window
#!/usr/bin/perl
#
# new-window
#
# public domain
#
use strict;
my $NAME = "TERMINAL";
my $SCREEN="/usr/bin/screen";
my $TITLE="win".time().".".(int(rand(10000));
my @out = `screen -list | fgrep $NAME`;
if (@out) {
my ($match,$attached) = ($out[0] =~
/\s*([0-9\-A-Za-z\.]+)\s*\(([A-Za-z]+)\)/);
sys("$SCREEN -U -S $match -X \"screen\" -t $TITLE");
sys("$SCREEN -U -S $match -X \"other\""); #undo the toggle
if ($attached eq 'Attached') {
sys("$SCREEN -U -r -x -p $TITLE -S $match")
} else {
sys("$SCREEN -U -r -p $TITLE -S $match")
}
} else {
sys("$SCREEN -U -x -R $NAME");
}
sub sys {
system(@_);
}
signature.asc
Description: OpenPGP digital signature
_______________________________________________ screen-users mailing list [email protected] http://lists.gnu.org/mailman/listinfo/screen-users
