[Top][All Lists]

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

Re: need "windowlist" info externally, not interactively

From: Amadeusz Sławiński
Subject: Re: need "windowlist" info externally, not interactively
Date: Mon, 19 Oct 2015 21:39:14 +0000

On Mon, 19 Oct 2015 20:47:34 +0200
Axel Beckert <address@hidden> wrote:

> Hi,
> On Sun, Oct 18, 2015 at 11:13:07PM +0000, Anonymous wrote:
> > A shell script needs to be able to add a window, and know in advance
> > what window number is still available.  It will then do some
> > stuffing.
> > 
> > ATM it's quite messy and complex.  The script attempts to randomly
> > create a title then use that as a handle, but then it must
> > eventually rename the window to something sensible.  Sometimes it
> > screws up and clobbers an existing window.
> Which screen commandline parameters do you use for that? I'd expect
> something like "screen -X screen 63 somecommand". (Would run
> "somecommand" in a window with number 63 unless that number is already
> in use.)
> > I need a more sensible option.  E.g. I need to be able to do
> > something like "screen -x user/session -windowlist", and simply get
> > a dump of windows, which the script can then parse.
> Have you tried "screen -Q windows"? Unfortunately it seems to be
> truncated to the width of the screen session's bottom line. Luckily it
> seems truncated at the beginning, i.e. you always see the highest
> number:
> Get the highest window number:
> $ screen -Q windows | sed -e
> 's/^.*[^0-9]\([0-9][0-9]*\)[^0-9]*\$[^$]*$/\1/' 10
> $
> Run "mc" in a window with one window number higher than the highest
> one (i.e. always a predetermined window number):
> $ screen -X screen $(($(screen -Q windows | sed -e
> 's/^.*[^0-9]\([0-9][0-9]*\)[^0-9]*\$[^$]*$/\1/')+1)) mc
> (needs bash or zsh for $((expression)) to work)
> Or separated to reuse the window number elsewhere:
> $ windownumber=$(($(screen -Q windows | sed -e
> 's/^.*[^0-9]\([0-9][0-9]*\)[^0-9]*\$[^$]*$/\1/')+1)) $ echo Window
> will be created with number $windownumber $ screen -X screen
> $windownumber mc
> HTH.
>               Kind regards, Axel


Just to add, on new versions (from 4.3.0) it is also possible to do
something like: screen -Q windows "%n %t\n"
to list window titles, it should return window numbers and titles on
separate lines

$ screen -S test -Q windows "%n %t\n"
0 zsh
1 zsh
2 zsh

You can use it to determine first free "missing number"
for example in 
$ screen -S test -Q windows "%n %t\n"
0 zsh
2 zsh
next window will be 1

or use in combination with 'collapse' command (also introduced in 4.3.0)

and then use wc -l to get window number

$ ./screen -Q windows "%n %t\n"
0 zsh
2 zsh
$ ./screen -X collapse
$ ./screen -Q windows "%n %t\n"
0 zsh
1 zsh
$ ./screen -Q windows "%n\n" | wc -l
$ windownumber=$(./screen -Q windows "%n\n" | wc -l)
$ echo $windownumber

Best Regards,

reply via email to

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