From 756591b4ca28089879ef785bde3a6fb30e9f5943 Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 12 Apr 2020 08:36:18 +0000 Subject: Add a -f filter argument to the list commands like choose-tree. --- cmd-list-windows.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'cmd-list-windows.c') diff --git a/cmd-list-windows.c b/cmd-list-windows.c index 46ee6f0c..32b7b8f5 100644 --- a/cmd-list-windows.c +++ b/cmd-list-windows.c @@ -49,8 +49,8 @@ const struct cmd_entry cmd_list_windows_entry = { .name = "list-windows", .alias = "lsw", - .args = { "F:at:", 0, 0 }, - .usage = "[-a] [-F format] " CMD_TARGET_SESSION_USAGE, + .args = { "F:f:at:", 0, 0 }, + .usage = "[-a] [-F format] [-f filter] " CMD_TARGET_SESSION_USAGE, .target = { 't', CMD_FIND_SESSION, 0 }, @@ -88,8 +88,9 @@ cmd_list_windows_session(struct cmd *self, struct session *s, struct winlink *wl; u_int n; struct format_tree *ft; - const char *template; - char *line; + const char *template, *filter; + char *line, *expanded; + int flag; template = args_get(args, 'F'); if (template == NULL) { @@ -102,6 +103,7 @@ cmd_list_windows_session(struct cmd *self, struct session *s, break; } } + filter = args_get(args, 'f'); n = 0; RB_FOREACH(wl, winlinks, &s->windows) { @@ -109,9 +111,17 @@ cmd_list_windows_session(struct cmd *self, struct session *s, format_add(ft, "line", "%u", n); format_defaults(ft, NULL, s, wl, NULL); - line = format_expand(ft, template); - cmdq_print(item, "%s", line); - free(line); + if (filter != NULL) { + expanded = format_expand(ft, filter); + flag = format_true(expanded); + free(expanded); + } else + flag = 1; + if (flag) { + line = format_expand(ft, template); + cmdq_print(item, "%s", line); + free(line); + } format_free(ft); n++; -- cgit From c20eb0c0ae3347c768894a6355adfd7ebae6f2f3 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 13 Apr 2020 08:26:27 +0000 Subject: Make struct cmd local to cmd.c and move it out of tmux.h. --- cmd-list-windows.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmd-list-windows.c') diff --git a/cmd-list-windows.c b/cmd-list-windows.c index 32b7b8f5..905e9eaf 100644 --- a/cmd-list-windows.c +++ b/cmd-list-windows.c @@ -61,7 +61,7 @@ const struct cmd_entry cmd_list_windows_entry = { static enum cmd_retval cmd_list_windows_exec(struct cmd *self, struct cmdq_item *item) { - struct args *args = self->args; + struct args *args = cmd_get_args(self); if (args_has(args, 'a')) cmd_list_windows_server(self, item); @@ -84,7 +84,7 @@ static void cmd_list_windows_session(struct cmd *self, struct session *s, struct cmdq_item *item, int type) { - struct args *args = self->args; + struct args *args = cmd_get_args(self); struct winlink *wl; u_int n; struct format_tree *ft; -- cgit