From 069f5925af8bf70a99eec7f4baf5772707e62def Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 21 Aug 2021 20:46:43 +0000 Subject: Preserve argument type in command and convert to string on demand. --- cmd-find-window.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'cmd-find-window.c') diff --git a/cmd-find-window.c b/cmd-find-window.c index 804e8fe4..6e07537c 100644 --- a/cmd-find-window.c +++ b/cmd-find-window.c @@ -48,7 +48,7 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item) struct cmd_find_state *target = cmdq_get_target(item); struct window_pane *wp = target->wp; const char *s = args_string(args, 0), *suffix = ""; - char *filter; + struct args_value *filter; int C, N, T; C = args_has(args, 'C'); @@ -65,31 +65,41 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item) if (!C && !N && !T) C = N = T = 1; + filter = xcalloc(1, sizeof *filter); + filter->type = ARGS_STRING; + if (C && N && T) { - xasprintf(&filter, + xasprintf(&filter->string, "#{||:" "#{C%s:%s},#{||:#{m%s:*%s*,#{window_name}}," "#{m%s:*%s*,#{pane_title}}}}", suffix, s, suffix, s, suffix, s); } else if (C && N) { - xasprintf(&filter, + xasprintf(&filter->string, "#{||:#{C%s:%s},#{m%s:*%s*,#{window_name}}}", suffix, s, suffix, s); } else if (C && T) { - xasprintf(&filter, + xasprintf(&filter->string, "#{||:#{C%s:%s},#{m%s:*%s*,#{pane_title}}}", suffix, s, suffix, s); } else if (N && T) { - xasprintf(&filter, + xasprintf(&filter->string, "#{||:#{m%s:*%s*,#{window_name}}," "#{m%s:*%s*,#{pane_title}}}", suffix, s, suffix, s); - } else if (C) - xasprintf(&filter, "#{C%s:%s}", suffix, s); - else if (N) - xasprintf(&filter, "#{m%s:*%s*,#{window_name}}", suffix, s); - else - xasprintf(&filter, "#{m%s:*%s*,#{pane_title}}", suffix, s); + } else if (C) { + xasprintf(&filter->string, + "#{C%s:%s}", + suffix, s); + } else if (N) { + xasprintf(&filter->string, + "#{m%s:*%s*,#{window_name}}", + suffix, s); + } else { + xasprintf(&filter->string, + "#{m%s:*%s*,#{pane_title}}", + suffix, s); + } new_args = args_create(); if (args_has(args, 'Z')) @@ -97,9 +107,7 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item) args_set(new_args, 'f', filter); window_pane_set_mode(wp, NULL, &window_tree_mode, target, new_args); - args_free(new_args); - free(filter); return (CMD_RETURN_NORMAL); } -- cgit v1.2.3