diff options
author | 2020-04-12 08:36:18 +0000 | |
---|---|---|
committer | 2020-04-12 08:36:18 +0000 | |
commit | a805fcb51a81ca00bb010f3bb85e4db9de11f9ff (patch) | |
tree | e0d996f9215c6417b133c425ed072b3e19ca70e7 /usr.bin/tmux/cmd-list-buffers.c | |
parent | Clarify a couple of style options. (diff) | |
download | wireguard-openbsd-a805fcb51a81ca00bb010f3bb85e4db9de11f9ff.tar.xz wireguard-openbsd-a805fcb51a81ca00bb010f3bb85e4db9de11f9ff.zip |
Add a -f filter argument to the list commands like choose-tree.
Diffstat (limited to 'usr.bin/tmux/cmd-list-buffers.c')
-rw-r--r-- | usr.bin/tmux/cmd-list-buffers.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/usr.bin/tmux/cmd-list-buffers.c b/usr.bin/tmux/cmd-list-buffers.c index 95d109d4826..d81ccc70cf9 100644 --- a/usr.bin/tmux/cmd-list-buffers.c +++ b/usr.bin/tmux/cmd-list-buffers.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-buffers.c,v 1.35 2017/05/01 12:20:55 nicm Exp $ */ +/* $OpenBSD: cmd-list-buffers.c,v 1.36 2020/04/12 08:36:18 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -36,8 +36,8 @@ const struct cmd_entry cmd_list_buffers_entry = { .name = "list-buffers", .alias = "lsb", - .args = { "F:", 0, 0 }, - .usage = "[-F format]", + .args = { "F:f:", 0, 0 }, + .usage = "[-F format] [-f filter]", .flags = CMD_AFTERHOOK, .exec = cmd_list_buffers_exec @@ -49,20 +49,30 @@ cmd_list_buffers_exec(struct cmd *self, struct cmdq_item *item) struct args *args = self->args; struct paste_buffer *pb; struct format_tree *ft; - char *line; - const char *template; + const char *template, *filter; + char *line, *expanded; + int flag; if ((template = args_get(args, 'F')) == NULL) template = LIST_BUFFERS_TEMPLATE; + filter = args_get(args, 'f'); pb = NULL; while ((pb = paste_walk(pb)) != NULL) { ft = format_create(item->client, item, FORMAT_NONE, 0); format_defaults_paste_buffer(ft, pb); - 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); } |