[patch] Searching window titles
Fernando Vezzosi <[email protected]> Wed, 22 Mar 2006 14:06:01 +0100
| Newsgroups | gmane.comp.gnu.screen |
|---|---|
| Message-ID | <[email protected]> |
Hi, I'm forwarding this message which awaits for moderator approval (I wasn't yet subscribed when I sent it). The patch is attached. bye ;) ----- Forwarded message from Fernando Vezzosi <[email protected]> ----- Date: Sun, 19 Mar 2006 23:33:23 +0100 From: Fernando Vezzosi <[email protected]> To: [email protected] Subject: [patch] Searching window titles User-Agent: Mutt/1.5.11+cvs20060126 X-Operating-System: Linux lothlorien 2.6.15-lothlorien #31337 Thu Jan 12 15:50:17 CET 2006 i686 GNU/Linux Hi everybody! I have produced this patch to be able to quickly switch to a window, by entering part of its name; I have called this function the "search" function; This is useful for users like me, who like to make their shell automatically change screen windows' titles with escape sequences, to reflect the command being run at the moment; Example usage: <userinput> ^A-/ <screen> "Search: " <userinput> file.c Alternatice: <userinput> ^A-: <userinput> search file.c screen switches to the window called: /home/buccia [ vim /home/buccia/c0de/file.c ] This diff is against 4.0.2; Apply with: patch -p1 < screen_search.patch Please anybody let me know if you find this useful ;) bye, -- Fernando Vezzosi 3F29 4D20 510E E1AE 991D 3B12 D6BE 7C05 B289 97C9 ----- End forwarded message ----- -- Fernando Vezzosi 3F29 4D20 510E E1AE 991D 3B12 D6BE 7C05 B289 97C9
fvezzosi.masobit.net_screen_search.patch
(text/plain, 3.2 KB)
diff -ur screen-4.0.2/comm.c /usr/local/src/screen-4.0.2/comm.c
--- screen-4.0.2/comm.c 2003-09-08 16:25:08.000000000 +0200
+++ /usr/local/src/screen-4.0.2/comm.c 2006-02-27 02:53:59.000000000 +0100
@@ -272,6 +272,7 @@
#ifdef COPY_PASTE
{ "scrollback", NEED_FORE|ARGS_1 },
#endif
+ { "search", ARGS_01 },
{ "select", ARGS_01 },
{ "sessionname", ARGS_01 },
{ "setenv", ARGS_012 },
diff -ur screen-4.0.2/doc/screen.1 /usr/local/src/screen-4.0.2/doc/screen.1
--- screen-4.0.2/doc/screen.1 2003-12-05 14:51:57.000000000 +0100
+++ /usr/local/src/screen-4.0.2/doc/screen.1 2006-03-19 22:27:30.000000000 +0100
@@ -384,6 +384,8 @@
The following table shows the default key bindings:
.IP "\fBC-a '\fP (select)"
Prompt for a window name or number to switch to.
+.IP "\fBC-a /\fP (search)"
+Prompt for a window name to search.
.IP "\fBC-a ""\fP (windowlist -b)"
Present a list of all windows for selection.
.IP "\fBC-a 0\fP (select 0)"
@@ -2575,6 +2577,14 @@
current setting.
.sp
.ne 3
+.BR "search " [ \fIText ]
+.PP
+Search for \fIText\fP in window names/titles.
+If any windows which contains \fIText\fP in the name are found, switch to
+the last used one. The parameter is optional and if omitted, you get
+prompted for a search text.
+.sp
+.ne 3
.BR "select " [ \fIWindowID ]
.PP
Switch to the window identified by \fIWindowID\fP.
diff -ur screen-4.0.2/process.c /usr/local/src/screen-4.0.2/process.c
--- screen-4.0.2/process.c 2003-09-18 14:53:54.000000000 +0200
+++ /usr/local/src/screen-4.0.2/process.c 2006-03-19 22:44:50.000000000 +0100
@@ -123,6 +123,8 @@
static int IsNum __P((char *, int));
static void Colonfin __P((char *, int, char *));
static void InputSelect __P((void));
+static void InputSearch __P((void));
+static void SearchFin __P((char *, int, char *));
static void InputSetenv __P((char *));
static void InputAKA __P((void));
#ifdef MULTIUSER
@@ -457,6 +459,7 @@
}
#endif
+ ktab['/'].nr = RC_SEARCH;
ktab['h'].nr = RC_HARDCOPY;
#ifdef BSDJOBS
ktab['z'].nr = ktab[Ctrl('z')].nr = RC_SUSPEND;
@@ -1073,6 +1076,12 @@
msgok = display && !*rc_name;
switch(nr)
{
+ case RC_SEARCH:
+ if(!*args)
+ InputSearch();
+ else
+ SearchFin(args[0], strlen(args[0]), NULL);
+ break;
case RC_SELECT:
if (!*args)
InputSelect();
@@ -5116,13 +5125,45 @@
return;
SwitchWindow(n);
}
-
+
+/*
+ * Search for a window title pattern.
+ * If we find any, switch to the first (which is the last used one)
+ * -- Fernando Vezzosi <[email protected]>
+ */
+static void
+SearchFin(buf, len, data)
+char *buf;
+int len;
+char *data;
+{
+ int i=0;
+ struct win *wptr;
+ if(!len || !display)
+ return;
+
+ for(wptr=windows; wptr; wptr=wptr->w_next, i++){
+ if(strstr(wptr->w_title, buf)){
+ SwitchWindow(wptr->w_number);
+/* Msg(0, "Found, crossed %d windows", i);*/
+ return;
+ }
+ }
+ Msg(0, "Pattern '%s' not found [%d windows]", buf, i);
+}
+
static void
InputSelect()
{
Input("Switch to window: ", 20, INP_COOKED, SelectFin, NULL);
}
+static void
+InputSearch()
+{
+ Input("Search: ", 100, INP_COOKED, SearchFin, NULL);
+}
+
static char setenv_var[31];
signature.asc
(application/pgp-signature, 191 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFEIUu51r58BbKJl8kRAvhZAJ99QsnBTVfIwowVO2544IpgcA8s2ACfcLxl 1eYeZNhK+01lq3czZRYUeXo= =ZvSB -----END PGP SIGNATURE-----