diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-03-20 17:09:49 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-03-20 17:09:49 +0000 |
commit | b477c986316276a67ba58c57e22dc8c37d830929 (patch) | |
tree | 7070a472c1565b5c5c33caa93a7495c39878753b | |
parent | 703a5fa04aedcee12c93ea8bd12423dcfde67db2 (diff) |
Add -C -N -T flags to find-window to find in content, name, title. From
Jonathan Daugherty.
-rw-r--r-- | usr.bin/tmux/cmd-find-window.c | 60 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 16 |
2 files changed, 66 insertions, 10 deletions
diff --git a/usr.bin/tmux/cmd-find-window.c b/usr.bin/tmux/cmd-find-window.c index 838fc00e07d..334d5fe1380 100644 --- a/usr.bin/tmux/cmd-find-window.c +++ b/usr.bin/tmux/cmd-find-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-find-window.c,v 1.8 2011/01/04 00:42:46 nicm Exp $ */ +/* $OpenBSD: cmd-find-window.c,v 1.9 2012/03/20 17:09:48 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -29,13 +29,25 @@ int cmd_find_window_exec(struct cmd *, struct cmd_ctx *); +u_int cmd_find_window_match_flags(struct args *); void cmd_find_window_callback(void *, int); void cmd_find_window_free(void *); +/* Flags for determining matching behavior. */ +#define CMD_FIND_WINDOW_BY_TITLE 0x1 +#define CMD_FIND_WINDOW_BY_CONTENT 0x2 +#define CMD_FIND_WINDOW_BY_NAME 0x4 + +#define CMD_FIND_WINDOW_ALL \ + (CMD_FIND_WINDOW_BY_TITLE | \ + CMD_FIND_WINDOW_BY_CONTENT | \ + CMD_FIND_WINDOW_BY_NAME) + + const struct cmd_entry cmd_find_window_entry = { "find-window", "findw", - "t:", 1, 1, - CMD_TARGET_WINDOW_USAGE " match-string", + "CNt:T", 1, 4, + "[-CNT] " CMD_TARGET_WINDOW_USAGE " match-string", 0, NULL, NULL, @@ -46,6 +58,26 @@ struct cmd_find_window_data { struct session *session; }; +u_int +cmd_find_window_match_flags(struct args *args) +{ + u_int match_flags = 0; + + /* Turn on flags based on the options. */ + if (args_has(args, 'T')) + match_flags |= CMD_FIND_WINDOW_BY_TITLE; + if (args_has(args, 'C')) + match_flags |= CMD_FIND_WINDOW_BY_CONTENT; + if (args_has(args, 'N')) + match_flags |= CMD_FIND_WINDOW_BY_NAME; + + /* If none of the flags were set, default to matching anything. */ + if (match_flags == 0) + match_flags = CMD_FIND_WINDOW_ALL; + + return match_flags; +} + int cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) { @@ -58,7 +90,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) ARRAY_DECL(, u_int) list_idx; ARRAY_DECL(, char *) list_ctx; char *str, *sres, *sctx, *searchstr; - u_int i, line; + u_int i, line, match_flags; if (ctx->curclient == NULL) { ctx->error(ctx, "must be run interactively"); @@ -69,6 +101,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) return (-1); + match_flags = cmd_find_window_match_flags(args); str = args->argv[0]; ARRAY_INIT(&list_idx); @@ -80,12 +113,25 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) TAILQ_FOREACH(wp, &wm->window->panes, entry) { i++; - if (fnmatch(searchstr, wm->window->name, 0) == 0) + if ((match_flags & CMD_FIND_WINDOW_BY_NAME) && + fnmatch(searchstr, wm->window->name, 0) == 0) sctx = xstrdup(""); else { - sres = window_pane_search(wp, str, &line); + sres = NULL; + if (match_flags & CMD_FIND_WINDOW_BY_CONTENT) { + sres = window_pane_search( + wp, str, &line); + } + + /* + * If match_title isn't set we don't want to + * bother checking the title, but that also + * constitutes a failure to match so we still + * want to abort. + */ if (sres == NULL && - fnmatch(searchstr, wp->base.title, 0) != 0) + (!(match_flags & CMD_FIND_WINDOW_BY_TITLE) || + fnmatch(searchstr, wp->base.title, 0) != 0)) continue; if (sres == NULL) { diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 7aa1bd9e92d..40e0b695328 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.284 2012/03/20 11:23:12 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.285 2012/03/20 17:09:48 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -1099,6 +1099,7 @@ to .Ql 9 keys. .It Xo Ic find-window +.Op Fl CNT .Op Fl t Ar target-window .Ar match-string .Xc @@ -1108,8 +1109,17 @@ Search for the pattern .Ar match-string in window names, titles, and visible content (but not history). -If only one window is matched, it'll be automatically selected, otherwise a -choice list is shown. +The flags control matching behavior: +.Fl C +matches only visible window contents, +.Fl N +matches only the window name and +.Fl T +matches only the window title. +The default is +.Fl CNT . +If only one window is matched, it'll be automatically selected, +otherwise a choice list is shown. This command only works from inside .Nm . .It Xo Ic join-pane |