diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2009-06-24 22:49:56 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2009-06-24 22:49:56 +0000 |
commit | 7e796dea035ed7028fc7188e65979725a24ff03d (patch) | |
tree | 2320aac0cebb0b6bf561a7d3a004622669ab174d /cmd-find-window.c | |
parent | 096cbf2ea558c0f66ee7bdaa8316e85c3e55ee69 (diff) |
Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern.
Also display the line number and the entire line in the results, and lose the
nasty section_string function and the now empty util.c file.
Initially from Tiago Cunha.
Diffstat (limited to 'cmd-find-window.c')
-rw-r--r-- | cmd-find-window.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/cmd-find-window.c b/cmd-find-window.c index 42637168..9458fa8b 100644 --- a/cmd-find-window.c +++ b/cmd-find-window.c @@ -18,6 +18,7 @@ #include <sys/types.h> +#include <fnmatch.h> #include <string.h> #include "tmux.h" @@ -58,8 +59,8 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) struct window_pane *wp; ARRAY_DECL(, u_int) list_idx; ARRAY_DECL(, char *) list_ctx; - char *sres, *sctx; - u_int i; + char *sres, *sctx, *searchstr; + u_int i, line; if (ctx->curclient == NULL) { ctx->error(ctx, "must be run interactively"); @@ -73,17 +74,18 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) ARRAY_INIT(&list_idx); ARRAY_INIT(&list_ctx); + xasprintf(&searchstr, "*%s*", data->arg); RB_FOREACH(wm, winlinks, &s->windows) { i = 0; TAILQ_FOREACH(wp, &wm->window->panes, entry) { i++; - if (strstr(wm->window->name, data->arg) != NULL) + if (fnmatch(searchstr, wm->window->name, 0) == 0) sctx = xstrdup(""); else { - sres = window_pane_search(wp, data->arg); + sres = window_pane_search(wp, data->arg, &line); if (sres == NULL && - strstr(wp->base.title, data->arg) == NULL) + fnmatch(searchstr, wp->base.title, 0) != 0) continue; if (sres == NULL) { @@ -91,7 +93,9 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) "pane %u title: \"%s\"", i - 1, wp->base.title); } else { - xasprintf(&sctx, "\"%s\"", sres); + xasprintf(&sctx, + "pane %u line %u: \"%s\"", i - 1, + line + 1, sres); xfree(sres); } } @@ -100,6 +104,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) ARRAY_ADD(&list_ctx, sctx); } } + xfree(searchstr); if (ARRAY_LENGTH(&list_idx) == 0) { ctx->error(ctx, "no windows matching: %s", data->arg); |