diff options
Diffstat (limited to 'usr.bin/tmux/cmd-list-sessions.c')
-rw-r--r-- | usr.bin/tmux/cmd-list-sessions.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/usr.bin/tmux/cmd-list-sessions.c b/usr.bin/tmux/cmd-list-sessions.c index db74ff21887..55f544b7cee 100644 --- a/usr.bin/tmux/cmd-list-sessions.c +++ b/usr.bin/tmux/cmd-list-sessions.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-sessions.c,v 1.30 2018/10/18 08:38:01 nicm Exp $ */ +/* $OpenBSD: cmd-list-sessions.c,v 1.31 2020/04/12 08:36:18 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -42,8 +42,8 @@ const struct cmd_entry cmd_list_sessions_entry = { .name = "list-sessions", .alias = "ls", - .args = { "F:", 0, 0 }, - .usage = "[-F format]", + .args = { "F:f:", 0, 0 }, + .usage = "[-F format] [-f filter]", .flags = CMD_AFTERHOOK, .exec = cmd_list_sessions_exec @@ -56,11 +56,13 @@ cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item) struct session *s; u_int n; struct format_tree *ft; - const char *template; - char *line; + const char *template, *filter; + char *line, *expanded; + int flag; if ((template = args_get(args, 'F')) == NULL) template = LIST_SESSIONS_TEMPLATE; + filter = args_get(args, 'f'); n = 0; RB_FOREACH(s, sessions, &sessions) { @@ -68,9 +70,17 @@ cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item) format_add(ft, "line", "%u", n); format_defaults(ft, NULL, s, NULL, 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++; |