[BACK]Return to cmd-find-window.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-find-window.c, Revision 1.49

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