screen-users
[Top][All Lists]
Advanced

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

[PATCH] screen: Introduce sort command


From: Thomas Renninger
Subject: [PATCH] screen: Introduce sort command
Date: Thu, 3 Mar 2011 14:38:24 +0100
User-agent: KMail/1.13.6 (Linux/2.6.38-rc4-0.0.27.08d159e-desktop; KDE/4.6.0; x86_64; ; )

Hi,

hope the mail goes through, please add me to CC on replies
as I am not subscribed on the list.


Below patch introduces a new command:
:sort

If in the overview window, showing all available screens,
this command will sort all windows after their name.

Why is this useful:
We maintain serial output of quite some terminal servers
in one screen, resulting in nearly 100 screens named after
the machine the screen instance shows the serial output for.

screenrc gets generated and already holds the window/machine names and 
it's already sorted.
But to get the screenrc active, the whole screen session must get
restarted, users might get thrown out, all screens have to reconnect, etc.
We try to avoid restarting the screen session whenever possible.

Therefore if a new serial console is added, it's added manually via
ctrl-a c (create), ctrl-a A (rename), ...
and it ends up at the end, not sorted.
Nobody will find the machine and sorting it with current commands (one 
up/down) is cumbersome.

There are probably other use-cases for this feature...

There is an issue with this patch: Sometimes the sort does not happen.
I did not debug it why, could be that it only happens if someone else
is using a screen window or similar.

Maybe someone who is more used to screen, could find out quickly why
this is?

Anyway, this happens rarely and the patch got tested for several years
in an older screen version. It still patches fine (5 line offset in one 
file) and should work.

Would be great if it can get included into the mainline code repository.

Thanks,

   Thomas

screen: Introduce sort command

Signed-off-by: Thomas Renninger <address@hidden>

 comm.c       |    1 +
 doc/screen.1 |    5 +++++
 process.c    |   41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)

Index: screen-4.0.2/comm.c
===================================================================
--- screen-4.0.2.orig/comm.c
+++ screen-4.0.2/comm.c
@@ -283,6 +283,7 @@
   { "sleep",           ARGS_1 },
   { "slowpaste",       NEED_FORE|ARGS_01 },
   { "sorendition",      ARGS_012 },
+  { "sort",            ARGS_0 },
   { "source",          ARGS_1 },
   { "split",           NEED_DISPLAY|ARGS_0 },
   { "startup_message", ARGS_1 },
Index: screen-4.0.2/process.c
===================================================================
--- screen-4.0.2.orig/process.c
+++ screen-4.0.2/process.c
@@ -2794,6 +2794,47 @@
          WindowChanged((struct win *)0, 0);
        }
       break;
+    case RC_SORT:
+      if (fore)
+        {
+         /* Better do not allow this. Not sure what the utmp stuff in number
+            command above is for (you get four entries in e.g. /var/log/wtmp
+            per number switch). But I don't know enough about this.*/
+         Msg(0, "Sorting inside a window is not allowed. Push CTRL-a \" "
+             "and try again\n");
+         break;
+       }
+      i = 0;
+      if (!wtab[i] || !wtab[i+1])
+        {
+         Msg(0, "Less than two windows, sorting makes no sense.\n");
+         break;
+       }
+      for (i = 0; wtab[i+1] != NULL; i++)
+        {
+         for (n = i, nr = i; wtab[n+1] != NULL; n++)
+           {
+             if (strcmp(wtab[nr]->w_title,wtab[n+1]->w_title) > 0)
+               {
+                 nr = n+1;
+               }
+           }
+         if (nr != i)
+           {
+             debug2("Exchange window %d and %d.\n", i, nr);
+             p = wtab[nr];
+             wtab[nr] = wtab[i];
+             wtab[i] = p;
+             wtab[nr]->w_number = nr;
+             wtab[i]->w_number = i;
+#ifdef MULTIUSER
+             /* exchange the acls for these windows. */
+             AclWinSwap(i, nr);
+#endif
+           }
+       }
+      WindowChanged((struct win *)0, 0);
+      break;
     case RC_SILENCE:
       n = fore->w_silence != 0;
       i = fore->w_silencewait;
Index: screen-4.0.2/doc/screen.1
===================================================================
--- screen-4.0.2.orig/doc/screen.1
+++ screen-4.0.2/doc/screen.1
@@ -2673,6 +2673,11 @@
 text. 
 .sp
 .ne 3
+.B sort
+.PP
+Sort the windows in alphabetical order of the window tiles.
+.sp
+.ne 3
 .BI "source " file
 .PP
 Read and execute commands from file \fIfile\fP. Source commands may

Attachment: sort_command.patch
Description: Text Data


reply via email to

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