Add -l flag to command-prompt to disable splitting into multiple prompts,

GitHub issue 4483.
This commit is contained in:
nicm
2025-10-29 09:37:36 +00:00
parent 1a419609e3
commit 2c08960f4e
2 changed files with 36 additions and 22 deletions

View File

@@ -42,8 +42,8 @@ const struct cmd_entry cmd_command_prompt_entry = {
.name = "command-prompt", .name = "command-prompt",
.alias = NULL, .alias = NULL,
.args = { "1bFkiI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse }, .args = { "1bFkliI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse },
.usage = "[-1bFkiN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE .usage = "[-1bFkliN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
" [-T prompt-type] [template]", " [-T prompt-type] [template]",
.flags = CMD_CLIENT_TFLAG, .flags = CMD_CLIENT_TFLAG,
@@ -117,27 +117,33 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
next_input = inputs = xstrdup(s); next_input = inputs = xstrdup(s);
else else
next_input = NULL; next_input = NULL;
while ((prompt = strsep(&next_prompt, ",")) != NULL) { if (args_has(args, 'l')) {
cdata->prompts = xreallocarray(cdata->prompts, cdata->count + 1, cdata->prompts = xcalloc(1, sizeof *cdata->prompts);
sizeof *cdata->prompts); cdata->prompts[0].prompt = prompts;
if (!space) cdata->prompts[0].input = inputs;
tmp = xstrdup(prompt); cdata->count = 1;
else } else {
xasprintf(&tmp, "%s ", prompt); while ((prompt = strsep(&next_prompt, ",")) != NULL) {
cdata->prompts[cdata->count].prompt = tmp; cdata->prompts = xreallocarray(cdata->prompts,
cdata->count + 1, sizeof *cdata->prompts);
if (!space)
tmp = xstrdup(prompt);
else
xasprintf(&tmp, "%s ", prompt);
cdata->prompts[cdata->count].prompt = tmp;
if (next_input != NULL) { if (next_input != NULL) {
input = strsep(&next_input, ","); input = strsep(&next_input, ",");
if (input == NULL) if (input == NULL)
input = "";
} else
input = ""; input = "";
} else cdata->prompts[cdata->count].input = xstrdup(input);
input = ""; cdata->count++;
cdata->prompts[cdata->count].input = xstrdup(input); }
free(inputs);
cdata->count++; free(prompts);
} }
free(inputs);
free(prompts);
if ((type = args_get(args, 'T')) != NULL) { if ((type = args_get(args, 'T')) != NULL) {
cdata->prompt_type = status_prompt_type(type); cdata->prompt_type = status_prompt_type(type);

12
tmux.1
View File

@@ -6670,7 +6670,7 @@ See
for possible values for for possible values for
.Ar prompt-type . .Ar prompt-type .
.It Xo Ic command-prompt .It Xo Ic command-prompt
.Op Fl 1bFikN .Op Fl 1bFiklN
.Op Fl I Ar inputs .Op Fl I Ar inputs
.Op Fl p Ar prompts .Op Fl p Ar prompts
.Op Fl t Ar target-client .Op Fl t Ar target-client
@@ -6690,8 +6690,10 @@ With
.Ar template .Ar template
is expanded as a format. is expanded as a format.
.Pp .Pp
If present, If
.Fl I .Fl I
is present,
.Ar inputs
is a comma-separated list of the initial text for each prompt. is a comma-separated list of the initial text for each prompt.
If If
.Fl p .Fl p
@@ -6703,6 +6705,12 @@ a single prompt is displayed, constructed from
if it is present, or if it is present, or
.Ql \&: .Ql \&:
if not. if not.
.Fl l
disables splitting of
.Ar inputs
and
.Ar prompts
at commas and treats them literally.
.Pp .Pp
Before the command is executed, the first occurrence of the string Before the command is executed, the first occurrence of the string
.Ql %% .Ql %%