screen-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Create a new window in screen without disturbing other screen sessions


From: abez
Subject: Create a new window in screen without disturbing other screen sessions
Date: Wed, 07 Nov 2007 15:28:10 -0500
User-agent: Thunderbird 1.5.0.14pre (X11/20071023)

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(@_);
}


Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]