summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2020-04-12 08:36:19 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2020-04-12 08:36:19 +0000
commit35909dba937aeadc697f2f22cbc96a82af619364 (patch)
tree5f3851f837bdcd683059377bca9cfdc57fec7e33 /usr.bin
parent166c61ab5981f6d0b94fb567b3727e81b3b65288 (diff)
Add a -f filter argument to the list commands like choose-tree.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cmd-list-buffers.c26
-rw-r--r--usr.bin/tmux/cmd-list-panes.c26
-rw-r--r--usr.bin/tmux/cmd-list-sessions.c26
-rw-r--r--usr.bin/tmux/cmd-list-windows.c26
-rw-r--r--usr.bin/tmux/tmux.138
5 files changed, 100 insertions, 42 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);
}
diff --git a/usr.bin/tmux/cmd-list-panes.c b/usr.bin/tmux/cmd-list-panes.c
index 6a9f99e6f77..34b369be6ad 100644
--- a/usr.bin/tmux/cmd-list-panes.c
+++ b/usr.bin/tmux/cmd-list-panes.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-list-panes.c,v 1.33 2017/05/01 12:20:55 nicm Exp $ */
+/* $OpenBSD: cmd-list-panes.c,v 1.34 2020/04/12 08:36:18 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -38,8 +38,8 @@ const struct cmd_entry cmd_list_panes_entry = {
.name = "list-panes",
.alias = "lsp",
- .args = { "asF:t:", 0, 0 },
- .usage = "[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
+ .args = { "asF:f:t:", 0, 0 },
+ .usage = "[-as] [-F format] [-f filter] " CMD_TARGET_WINDOW_USAGE,
.target = { 't', CMD_FIND_WINDOW, 0 },
@@ -91,8 +91,9 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
struct window_pane *wp;
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) {
@@ -120,6 +121,7 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
break;
}
}
+ filter = args_get(args, 'f');
n = 0;
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
@@ -127,9 +129,17 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
format_add(ft, "line", "%u", n);
format_defaults(ft, NULL, s, wl, wp);
- 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++;
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++;
diff --git a/usr.bin/tmux/cmd-list-windows.c b/usr.bin/tmux/cmd-list-windows.c
index 4eebbbc6a59..ce484010aa8 100644
--- a/usr.bin/tmux/cmd-list-windows.c
+++ b/usr.bin/tmux/cmd-list-windows.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-list-windows.c,v 1.43 2017/05/01 12:20:55 nicm Exp $ */
+/* $OpenBSD: cmd-list-windows.c,v 1.44 2020/04/12 08:36:18 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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++;
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index a972f307e16..015c2225e3c 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.737 2020/04/12 08:13:41 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.738 2020/04/12 08:36:18 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -1055,12 +1055,18 @@ List the syntax of
.Ar command
or - if omitted - of all commands supported by
.Nm .
-.It Ic list-sessions Op Fl F Ar format
+.It Xo Ic list-sessions
+.Op Fl F Ar format
+.Op Fl f Ar filter
+.Xc
.D1 (alias: Ic ls )
List all sessions managed by the server.
-For the meaning of the
.Fl F
-flag, see the
+specifies the format of each line and
+.Fl f
+a filter.
+Only sessions for which the filter is true are shown.
+See the
.Sx FORMATS
section.
.It Ic lock-client Op Fl t Ar target-client
@@ -2062,6 +2068,7 @@ is given, the newly linked window is not selected.
.It Xo Ic list-panes
.Op Fl as
.Op Fl F Ar format
+.Op Fl f Ar filter
.Op Fl t Ar target
.Xc
.D1 (alias: Ic lsp )
@@ -2078,14 +2085,18 @@ is a session (or the current session).
If neither is given,
.Ar target
is a window (or the current window).
-For the meaning of the
.Fl F
-flag, see the
+specifies the format of each line and
+.Fl f
+a filter.
+Only panes for which the filter is true are shown.
+See the
.Sx FORMATS
section.
.It Xo Ic list-windows
.Op Fl a
.Op Fl F Ar format
+.Op Fl f Ar filter
.Op Fl t Ar target-session
.Xc
.D1 (alias: Ic lsw )
@@ -2094,9 +2105,12 @@ If
is given, list all windows on the server.
Otherwise, list windows in the current session or in
.Ar target-session .
-For the meaning of the
.Fl F
-flag, see the
+specifies the format of each line and
+.Fl f
+a filter.
+Only windows for which the filter is true are shown.
+See the
.Sx FORMATS
section.
.It Xo Ic move-pane
@@ -5261,12 +5275,16 @@ Delete the buffer named
or the most recently added automatically named buffer if not specified.
.It Xo Ic list-buffers
.Op Fl F Ar format
+.Op Fl f Ar filter
.Xc
.D1 (alias: Ic lsb )
List the global buffers.
-For the meaning of the
.Fl F
-flag, see the
+specifies the format of each line and
+.Fl f
+a filter.
+Only buffers for which the filter is true are shown.
+See the
.Sx FORMATS
section.
.It Xo Ic load-buffer