Add a -f filter argument to the list commands like choose-tree.

pull/2172/head
nicm 2020-04-12 08:36:18 +00:00
parent 70534cfde6
commit 756591b4ca
5 changed files with 95 additions and 37 deletions

View File

@ -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);
}

View File

@ -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++;

View File

@ -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++;

View File

@ -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++;

36
tmux.1
View File

@ -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