screen-users
[Top][All Lists]
Advanced

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

[PATCH] screen -F


From: Johannes Weiner
Subject: [PATCH] screen -F
Date: Thu, 27 Sep 2007 13:59:30 +0200
User-agent: Mutt/1.5.16 (2007-06-11)

Hi,

I have sent this patch to screen-devel already a long time ago, but it was not
noticed.

This patch extends the built in `screen' command, to allow raising a window by
its title or newly creating it if no window with that title is found, e.g.:
        screen -F -t emacs emacs
Called the first time, this starts emacs in the window titled `emacs'.
Called the second time, this finds the window named `emacs' and selects it.

        Hannes

PS: If this patch has chances to be applied, I will write documentation for
it.  And what about the `screen' executable itself?  Should it implement -F
too?

-- 
3BD8 AF56 11AF 205C 9DB6  B10F 76F1 0634 71A4 DCA0
# TODO: Documentation

diff -Naur screen.old/src/extern.h screen/src/extern.h
--- screen.old/src/extern.h     2007-05-29 19:59:51.000000000 +0200
+++ screen/src/extern.h 2007-05-29 20:00:44.000000000 +0200
@@ -132,6 +132,7 @@
 
 /* window.c */
 extern int   MakeWindow __P((struct NewWindow *));
+extern int   FindOrMakeWindow __P((struct NewWindow *));
 extern int   RemakeWindow __P((struct win *));
 extern void  FreeWindow __P((struct win *));
 #ifdef PSEUDOS
diff -Naur screen.old/src/process.c screen/src/process.c
--- screen.old/src/process.c    2007-05-29 19:59:51.000000000 +0200
+++ screen/src/process.c        2007-05-29 20:00:04.000000000 +0200
@@ -5569,6 +5569,7 @@
 DoScreen(fn, av)
 char *fn, **av;
 {
+  int find = 0;
   struct NewWindow nwin;
   register int num;
   char buf[20];
@@ -5602,6 +5603,9 @@
              break;
            }
          break;
+       case 'F':
+         find = 1;
+         break;
        case 't':       /* no more -k */
          if (av[0][2])
            nwin.aka = &av[0][2];
@@ -5682,7 +5686,10 @@
       if (!nwin.aka)
         nwin.aka = Filename(*av);
     }
-  MakeWindow(&nwin);
+  if (find)
+    FindOrMakeWindow(&nwin);
+  else
+    MakeWindow(&nwin);
 }
 
 #ifdef COPY_PASTE
diff -Naur screen.old/src/window.c screen/src/window.c
--- screen.old/src/window.c     2007-05-29 19:59:51.000000000 +0200
+++ screen/src/window.c 2007-05-29 20:00:04.000000000 +0200
@@ -846,6 +846,40 @@
 }
 
 /*
+ * Look up a window via its title. If it's found, it is just fetched to the
+ * foreground. If not, it gets created with the given flags.
+ */
+int
+FindOrMakeWindow(nwin)
+struct NewWindow *nwin;
+{
+  struct win *r = NULL, *p = windows;
+
+  if (!nwin->aka)
+    {
+      Msg(0, "Window lookup impossible without title, creating new.");
+      return MakeWindow(nwin);
+    }
+
+  while (p)
+    {
+      if (strcmp(nwin->aka, p->w_title) == 0)
+       {
+         r = p;
+         break;
+       }
+      p = p->w_next;
+    }
+
+  if (r)
+    SwitchWindow(r->w_number);
+  else
+    return MakeWindow(nwin);
+
+  return 0;
+}
+
+/*
  * Resurrect a window from Zombie state.
  * The command vector is therefore stored in the window structure.
  * Note: The terminaltype defaults to screenterm again, the current

Attachment: signature.asc
Description: Digital signature


reply via email to

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