From 1e5f93b7b633b47518e57cfb8b060069cf6cc9f3 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 14 Jan 2026 19:43:43 +0000 Subject: [PATCH] Add -e flag to command-prompt to close if empty, from Dane Jensen in GitHub issue 4812. --- cmd-command-prompt.c | 10 ++++++---- status.c | 5 +++++ tmux.1 | 6 +++++- tmux.h | 1 + 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c index 85a1bf8a..e5c2b12c 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -42,8 +42,8 @@ const struct cmd_entry cmd_command_prompt_entry = { .name = "command-prompt", .alias = NULL, - .args = { "1bFkliI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse }, - .usage = "[-1bFkliN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE + .args = { "1beFiklI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse }, + .usage = "[-1beFiklN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " [-T prompt-type] [template]", .flags = CMD_CLIENT_TFLAG, @@ -84,7 +84,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item) struct client *tc = cmdq_get_target_client(item); struct cmd_find_state *target = cmdq_get_target(item); const char *type, *s, *input; - struct cmd_command_prompt_cdata *cdata; + struct cmd_command_prompt_cdata *cdata; char *tmp, *prompts, *prompt, *next_prompt; char *inputs = NULL, *next_input; u_int count = args_count(args); @@ -163,6 +163,8 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item) cdata->flags |= PROMPT_INCREMENTAL; else if (args_has(args, 'k')) cdata->flags |= PROMPT_KEY; + else if (args_has(args, 'e')) + cdata->flags |= PROMPT_BSPACE_EXIT; status_prompt_set(tc, target, cdata->prompts[0].prompt, cdata->prompts[0].input, cmd_command_prompt_callback, cmd_command_prompt_free, cdata, cdata->flags, cdata->prompt_type); @@ -234,7 +236,7 @@ out: static void cmd_command_prompt_free(void *data) { - struct cmd_command_prompt_cdata *cdata = data; + struct cmd_command_prompt_cdata *cdata = data; u_int i; for (i = 0; i < cdata->count; i++) { diff --git a/status.c b/status.c index 79ce9cad..edbb04ad 100644 --- a/status.c +++ b/status.c @@ -1383,6 +1383,11 @@ process_key: break; case KEYC_BSPACE: case 'h'|KEYC_CTRL: + if (c->prompt_flags & PROMPT_BSPACE_EXIT && size == 0) { + if (c->prompt_inputcb(c, c->prompt_data, NULL, 1) == 0) + status_prompt_clear(c); + break; + } if (c->prompt_index != 0) { if (c->prompt_index == size) c->prompt_buffer[--c->prompt_index].size = 0; diff --git a/tmux.1 b/tmux.1 index 4b88e203..bf051794 100644 --- a/tmux.1 +++ b/tmux.1 @@ -6716,7 +6716,7 @@ See for possible values for .Ar prompt-type . .It Xo Ic command-prompt -.Op Fl 1bFiklN +.Op Fl 1beFiklN .Op Fl I Ar inputs .Op Fl p Ar prompts .Op Fl t Ar target-client @@ -6789,6 +6789,10 @@ makes the prompt only accept numeric key presses. .Fl i executes the command every time the prompt input changes instead of when the user exits the command prompt. +.Fl e +makes +.Em BSpace +cancel an empty prompt. .Pp .Fl T tells diff --git a/tmux.h b/tmux.h index a3604935..e14113ff 100644 --- a/tmux.h +++ b/tmux.h @@ -2054,6 +2054,7 @@ struct client { #define PROMPT_KEY 0x10 #define PROMPT_ACCEPT 0x20 #define PROMPT_QUOTENEXT 0x40 +#define PROMPT_BSPACE_EXIT 0x80 int prompt_flags; enum prompt_type prompt_type; int prompt_cursor;