Add -y flag to disable confirmation prompts in modes, GitHub issue 4152.

This commit is contained in:
nicm 2024-10-04 19:16:13 +00:00
parent 34775fc235
commit 5a68730e2f
6 changed files with 48 additions and 13 deletions

View File

@ -33,7 +33,7 @@ const struct cmd_entry cmd_choose_tree_entry = {
.name = "choose-tree",
.alias = NULL,
.args = { "F:f:GK:NO:rst:wZ", 0, 1, cmd_choose_tree_args_parse },
.args = { "F:f:GK:NO:rst:wyZ", 0, 1, cmd_choose_tree_args_parse },
.usage = "[-GNrswZ] [-F format] [-f filter] [-K key-format] "
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
@ -47,7 +47,7 @@ const struct cmd_entry cmd_choose_client_entry = {
.name = "choose-client",
.alias = NULL,
.args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
.args = { "F:f:K:NO:rt:yZ", 0, 1, cmd_choose_tree_args_parse },
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
@ -61,7 +61,7 @@ const struct cmd_entry cmd_choose_buffer_entry = {
.name = "choose-buffer",
.alias = NULL,
.args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
.args = { "F:f:K:NO:rt:yZ", 0, 1, cmd_choose_tree_args_parse },
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
@ -75,7 +75,7 @@ const struct cmd_entry cmd_customize_mode_entry = {
.name = "customize-mode",
.alias = NULL,
.args = { "F:f:Nt:Z", 0, 0, NULL },
.args = { "F:f:Nt:yZ", 0, 0, NULL },
.usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE,
.target = { 't', CMD_FIND_PANE, 0 },

View File

@ -598,6 +598,19 @@ status_message_redraw(struct client *c)
return (1);
}
/* Accept prompt immediately. */
static enum cmd_retval
status_prompt_accept(__unused struct cmdq_item *item, void *data)
{
struct client *c = data;
if (c->prompt_string != NULL) {
c->prompt_inputcb(c, c->prompt_data, "y", 1);
status_prompt_clear(c);
}
return (CMD_RETURN_NORMAL);
}
/* Enable status line prompt. */
void
status_prompt_set(struct client *c, struct cmd_find_state *fs,
@ -655,6 +668,9 @@ status_prompt_set(struct client *c, struct cmd_find_state *fs,
free(tmp);
format_free(ft);
if ((flags & PROMPT_SINGLE) && (flags & PROMPT_ACCEPT))
cmdq_append(c, cmdq_get_callback(status_prompt_accept, c));
}
/* Remove status line prompt. */

12
tmux.1
View File

@ -2581,7 +2581,7 @@ the end of the visible pane.
The default is to capture only the visible contents of the pane.
.It Xo
.Ic choose-client
.Op Fl NrZ
.Op Fl NryZ
.Op Fl F Ar format
.Op Fl f Ar filter
.Op Fl K Ar key-format
@ -2597,6 +2597,8 @@ or the list may be navigated and an item chosen or otherwise manipulated using
the keys below.
.Fl Z
zooms the pane.
.Fl y
disables any confirmation prompts.
The following keys may be used in client mode:
.Bl -column "Key" "Function" -offset indent
.It Sy "Key" Ta Sy "Function"
@ -2655,7 +2657,7 @@ starts without the preview or if given twice with the larger preview.
This command works only if at least one client is attached.
.It Xo
.Ic choose-tree
.Op Fl GNrswZ
.Op Fl GNrswyZ
.Op Fl F Ar format
.Op Fl f Ar filter
.Op Fl K Ar key-format
@ -2675,6 +2677,8 @@ starts with sessions collapsed and
with windows collapsed.
.Fl Z
zooms the pane.
.Fl y
disables any confirmation prompts.
The following keys may be used in tree mode:
.Bl -column "Key" "Function" -offset indent
.It Sy "Key" Ta Sy "Function"
@ -6807,7 +6811,7 @@ The buffer commands are as follows:
.Bl -tag -width Ds
.It Xo
.Ic choose-buffer
.Op Fl NZr
.Op Fl NryZ
.Op Fl F Ar format
.Op Fl f Ar filter
.Op Fl K Ar key-format
@ -6823,6 +6827,8 @@ or the list may be navigated and an item chosen or otherwise manipulated using
the keys below.
.Fl Z
zooms the pane.
.Fl y
disables any confirmation prompts.
The following keys may be used in buffer mode:
.Bl -column "Key" "Function" -offset indent
.It Sy "Key" Ta Sy "Function"

1
tmux.h
View File

@ -1935,6 +1935,7 @@ struct client {
#define PROMPT_INCREMENTAL 0x4
#define PROMPT_NOFORMAT 0x8
#define PROMPT_KEY 0x10
#define PROMPT_ACCEPT 0x20
int prompt_flags;
enum prompt_type prompt_type;
int prompt_cursor;

View File

@ -101,6 +101,7 @@ struct window_customize_modedata {
struct mode_tree_data *data;
char *format;
int hide_global;
int prompt_flags;
struct window_customize_itemdata **item_list;
u_int item_size;
@ -885,6 +886,8 @@ window_customize_init(struct window_mode_entry *wme, struct cmd_find_state *fs,
data->format = xstrdup(WINDOW_CUSTOMIZE_DEFAULT_FORMAT);
else
data->format = xstrdup(args_get(args, 'F'));
if (args_has(args, 'y'))
data->prompt_flags = PROMPT_ACCEPT;
data->data = mode_tree_start(wp, args, window_customize_build,
window_customize_draw, NULL, window_customize_menu,
@ -1453,7 +1456,8 @@ window_customize_key(struct window_mode_entry *wme, struct client *c,
status_prompt_set(c, NULL, prompt, "",
window_customize_change_current_callback,
window_customize_free_callback, data,
PROMPT_SINGLE|PROMPT_NOFORMAT, PROMPT_TYPE_COMMAND);
PROMPT_SINGLE|PROMPT_NOFORMAT|data->prompt_flags,
PROMPT_TYPE_COMMAND);
free(prompt);
break;
case 'D':
@ -1466,7 +1470,8 @@ window_customize_key(struct window_mode_entry *wme, struct client *c,
status_prompt_set(c, NULL, prompt, "",
window_customize_change_tagged_callback,
window_customize_free_callback, data,
PROMPT_SINGLE|PROMPT_NOFORMAT, PROMPT_TYPE_COMMAND);
PROMPT_SINGLE|PROMPT_NOFORMAT|data->prompt_flags,
PROMPT_TYPE_COMMAND);
free(prompt);
break;
case 'u':
@ -1482,7 +1487,8 @@ window_customize_key(struct window_mode_entry *wme, struct client *c,
status_prompt_set(c, NULL, prompt, "",
window_customize_change_current_callback,
window_customize_free_callback, data,
PROMPT_SINGLE|PROMPT_NOFORMAT, PROMPT_TYPE_COMMAND);
PROMPT_SINGLE|PROMPT_NOFORMAT|data->prompt_flags,
PROMPT_TYPE_COMMAND);
free(prompt);
break;
case 'U':
@ -1495,7 +1501,8 @@ window_customize_key(struct window_mode_entry *wme, struct client *c,
status_prompt_set(c, NULL, prompt, "",
window_customize_change_tagged_callback,
window_customize_free_callback, data,
PROMPT_SINGLE|PROMPT_NOFORMAT, PROMPT_TYPE_COMMAND);
PROMPT_SINGLE|PROMPT_NOFORMAT|data->prompt_flags,
PROMPT_TYPE_COMMAND);
free(prompt);
break;
case 'H':

View File

@ -131,6 +131,7 @@ struct window_tree_modedata {
char *key_format;
char *command;
int squash_groups;
int prompt_flags;
struct window_tree_itemdata **item_list;
u_int item_size;
@ -934,6 +935,8 @@ window_tree_init(struct window_mode_entry *wme, struct cmd_find_state *fs,
else
data->command = xstrdup(args_string(args, 0));
data->squash_groups = !args_has(args, 'G');
if (args_has(args, 'y'))
data->prompt_flags = PROMPT_ACCEPT;
data->data = mode_tree_start(wp, args, window_tree_build,
window_tree_draw, window_tree_search, window_tree_menu, NULL,
@ -1305,7 +1308,8 @@ again:
data->references++;
status_prompt_set(c, NULL, prompt, "",
window_tree_kill_current_callback, window_tree_command_free,
data, PROMPT_SINGLE|PROMPT_NOFORMAT, PROMPT_TYPE_COMMAND);
data, PROMPT_SINGLE|PROMPT_NOFORMAT|data->prompt_flags,
PROMPT_TYPE_COMMAND);
free(prompt);
break;
case 'X':
@ -1316,7 +1320,8 @@ again:
data->references++;
status_prompt_set(c, NULL, prompt, "",
window_tree_kill_tagged_callback, window_tree_command_free,
data, PROMPT_SINGLE|PROMPT_NOFORMAT, PROMPT_TYPE_COMMAND);
data, PROMPT_SINGLE|PROMPT_NOFORMAT|data->prompt_flags,
PROMPT_TYPE_COMMAND);
free(prompt);
break;
case ':':