Home | History | Annotate | Line # | Download | only in dist
      1   1.1.1.5  christos /* $OpenBSD$ */
      2       1.1      jmmv 
      3       1.1      jmmv /*
      4   1.1.1.6  christos  * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott (at) gmail.com>
      5       1.1      jmmv  *
      6       1.1      jmmv  * Permission to use, copy, modify, and distribute this software for any
      7       1.1      jmmv  * purpose with or without fee is hereby granted, provided that the above
      8       1.1      jmmv  * copyright notice and this permission notice appear in all copies.
      9       1.1      jmmv  *
     10       1.1      jmmv  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     11       1.1      jmmv  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     12       1.1      jmmv  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     13       1.1      jmmv  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     14       1.1      jmmv  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
     15       1.1      jmmv  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
     16       1.1      jmmv  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     17       1.1      jmmv  */
     18       1.1      jmmv 
     19       1.1      jmmv #include <sys/types.h>
     20       1.1      jmmv 
     21   1.1.1.3  christos #include <stdlib.h>
     22       1.1      jmmv 
     23       1.1      jmmv #include "tmux.h"
     24       1.1      jmmv 
     25       1.1      jmmv /*
     26       1.1      jmmv  * Find window containing text.
     27       1.1      jmmv  */
     28       1.1      jmmv 
     29   1.1.1.7  christos static enum cmd_retval	cmd_find_window_exec(struct cmd *, struct cmdq_item *);
     30       1.1      jmmv 
     31       1.1      jmmv const struct cmd_entry cmd_find_window_entry = {
     32   1.1.1.6  christos 	.name = "find-window",
     33   1.1.1.6  christos 	.alias = "findw",
     34   1.1.1.6  christos 
     35  1.1.1.12       wiz 	.args = { "CiNrt:TZ", 1, 1, NULL },
     36  1.1.1.11  christos 	.usage = "[-CiNrTZ] " CMD_TARGET_PANE_USAGE " match-string",
     37   1.1.1.6  christos 
     38   1.1.1.8  christos 	.target = { 't', CMD_FIND_PANE, 0 },
     39   1.1.1.6  christos 
     40   1.1.1.6  christos 	.flags = 0,
     41   1.1.1.6  christos 	.exec = cmd_find_window_exec
     42       1.1      jmmv };
     43       1.1      jmmv 
     44   1.1.1.7  christos static enum cmd_retval
     45   1.1.1.7  christos cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
     46       1.1      jmmv {
     47  1.1.1.11  christos 	struct args		*args = cmd_get_args(self), *new_args;
     48  1.1.1.11  christos 	struct cmd_find_state	*target = cmdq_get_target(item);
     49  1.1.1.11  christos 	struct window_pane	*wp = target->wp;
     50  1.1.1.12       wiz 	const char		*s = args_string(args, 0), *suffix = "";
     51  1.1.1.13       wiz 	const char		*star = "*";
     52  1.1.1.12       wiz 	struct args_value	*filter;
     53   1.1.1.8  christos 	int			 C, N, T;
     54   1.1.1.8  christos 
     55   1.1.1.8  christos 	C = args_has(args, 'C');
     56   1.1.1.8  christos 	N = args_has(args, 'N');
     57   1.1.1.8  christos 	T = args_has(args, 'T');
     58   1.1.1.8  christos 
     59  1.1.1.13       wiz 	if (args_has(args, 'r'))
     60  1.1.1.13       wiz 		star = "";
     61  1.1.1.11  christos 	if (args_has(args, 'r') && args_has(args, 'i'))
     62  1.1.1.11  christos 		suffix = "/ri";
     63  1.1.1.11  christos 	else if (args_has(args, 'r'))
     64  1.1.1.11  christos 		suffix = "/r";
     65  1.1.1.11  christos 	else if (args_has(args, 'i'))
     66  1.1.1.11  christos 		suffix = "/i";
     67  1.1.1.11  christos 
     68   1.1.1.8  christos 	if (!C && !N && !T)
     69   1.1.1.8  christos 		C = N = T = 1;
     70   1.1.1.8  christos 
     71  1.1.1.12       wiz 	filter = xcalloc(1, sizeof *filter);
     72  1.1.1.12       wiz 	filter->type = ARGS_STRING;
     73  1.1.1.12       wiz 
     74  1.1.1.11  christos 	if (C && N && T) {
     75  1.1.1.12       wiz 		xasprintf(&filter->string,
     76  1.1.1.11  christos 		    "#{||:"
     77  1.1.1.13       wiz 		    "#{C%s:%s},#{||:#{m%s:%s%s%s,#{window_name}},"
     78  1.1.1.13       wiz 		    "#{m%s:%s%s%s,#{pane_title}}}}",
     79  1.1.1.13       wiz 		    suffix, s, suffix, star, s, star, suffix, star, s, star);
     80  1.1.1.11  christos 	} else if (C && N) {
     81  1.1.1.12       wiz 		xasprintf(&filter->string,
     82  1.1.1.13       wiz 		    "#{||:#{C%s:%s},#{m%s:%s%s%s,#{window_name}}}",
     83  1.1.1.13       wiz 		    suffix, s, suffix, star, s, star);
     84  1.1.1.11  christos 	} else if (C && T) {
     85  1.1.1.12       wiz 		xasprintf(&filter->string,
     86  1.1.1.13       wiz 		    "#{||:#{C%s:%s},#{m%s:%s%s%s,#{pane_title}}}",
     87  1.1.1.13       wiz 		    suffix, s, suffix, star, s, star);
     88  1.1.1.11  christos 	} else if (N && T) {
     89  1.1.1.12       wiz 		xasprintf(&filter->string,
     90  1.1.1.13       wiz 		    "#{||:#{m%s:%s%s%s,#{window_name}},"
     91  1.1.1.13       wiz 		    "#{m%s:%s%s%s,#{pane_title}}}",
     92  1.1.1.13       wiz 		    suffix, star, s, star, suffix, star, s, star);
     93  1.1.1.12       wiz 	} else if (C) {
     94  1.1.1.12       wiz 		xasprintf(&filter->string,
     95  1.1.1.12       wiz 		    "#{C%s:%s}",
     96  1.1.1.12       wiz 		    suffix, s);
     97  1.1.1.12       wiz 	} else if (N) {
     98  1.1.1.12       wiz 		xasprintf(&filter->string,
     99  1.1.1.13       wiz 		    "#{m%s:%s%s%s,#{window_name}}",
    100  1.1.1.13       wiz 		    suffix, star, s, star);
    101  1.1.1.12       wiz 	} else {
    102  1.1.1.12       wiz 		xasprintf(&filter->string,
    103  1.1.1.13       wiz 		    "#{m%s:%s%s%s,#{pane_title}}",
    104  1.1.1.13       wiz 		    suffix, star, s, star);
    105  1.1.1.12       wiz 	}
    106       1.1      jmmv 
    107  1.1.1.12       wiz 	new_args = args_create();
    108   1.1.1.9  christos 	if (args_has(args, 'Z'))
    109  1.1.1.13       wiz 		args_set(new_args, 'Z', NULL, 0);
    110  1.1.1.13       wiz 	args_set(new_args, 'f', filter, 0);
    111       1.1      jmmv 
    112  1.1.1.11  christos 	window_pane_set_mode(wp, NULL, &window_tree_mode, target, new_args);
    113   1.1.1.8  christos 	args_free(new_args);
    114   1.1.1.8  christos 
    115   1.1.1.8  christos 	return (CMD_RETURN_NORMAL);
    116       1.1      jmmv }
    117