Preserve file and flags.

This commit is contained in:
Nicholas Marriott
2026-06-30 17:37:15 +01:00
parent 08500f844d
commit c92720e3b0
5 changed files with 68 additions and 12 deletions

View File

@@ -58,6 +58,8 @@ struct cmd_command_prompt_prompt {
struct cmd_command_prompt_cdata { struct cmd_command_prompt_cdata {
struct cmdq_item *item; struct cmdq_item *item;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
char *file;
int parse_flags;
int flags; int flags;
enum prompt_type prompt_type; enum prompt_type prompt_type;
@@ -85,7 +87,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
struct args *args = cmd_get_args(self); struct args *args = cmd_get_args(self);
struct client *tc = cmdq_get_target_client(item); struct client *tc = cmdq_get_target_client(item);
struct cmd_find_state *target = cmdq_get_target(item); struct cmd_find_state *target = cmdq_get_target(item);
const char *type, *s, *input, *cmd; const char *type, *s, *input, *cmd, *file;
struct cmd_command_prompt_cdata *cdata; struct cmd_command_prompt_cdata *cdata;
char *tmp, *prompts, *prompt, *next_prompt; char *tmp, *prompts, *prompt, *next_prompt;
char *inputs = NULL, *next_input, *cause = NULL; char *inputs = NULL, *next_input, *cause = NULL;
@@ -116,6 +118,10 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
free(cdata); free(cdata);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
cmd_get_source(self, &file, NULL);
if (file != NULL)
cdata->file = xstrdup(file);
cdata->parse_flags = cmd_get_parse_flags(self);
} }
if ((s = args_get(args, 'p')) == NULL) { if ((s = args_get(args, 'p')) == NULL) {
@@ -253,14 +259,16 @@ cmd_command_prompt_callback(struct client *c, void *data, const char *s,
/* Explicit body: prompt inputs become the template argv. */ /* Explicit body: prompt inputs become the template argv. */
ci.argc = argc; ci.argc = argc;
ci.argv = argv; ci.argv = argv;
ci.file = cdata->file;
ci.flags = cdata->parse_flags;
new_item = cmd_invoke_get(cdata->tree, cs, &ci); new_item = cmd_invoke_get(cdata->tree, cs, &ci);
if (item == NULL) if (item == NULL)
cmdq_append(c, new_item); cmdq_append(c, new_item);
else else
cmdq_insert_after(item, new_item); cmdq_insert_after(item, new_item);
} else { } else if (argc > 0 && argv[0] != NULL) {
/* No body: parse the submitted text as command language. */ /* No body: parse the submitted text as command language. */
tree = cmd_parse_from_string(s, &pi, &error); tree = cmd_parse_from_string(argv[0], &pi, &error);
if (tree == NULL) { if (tree == NULL) {
if (item == NULL) if (item == NULL)
cmdq_append(c, cmdq_get_error(error)); cmdq_append(c, cmdq_get_error(error));
@@ -312,5 +320,6 @@ cmd_command_prompt_free(void *data)
free(cdata->prompts); free(cdata->prompts);
cmd_free_argv(cdata->argc, cdata->argv); cmd_free_argv(cdata->argc, cdata->argv);
cmd_parse_free(cdata->tree); cmd_parse_free(cdata->tree);
free(cdata->file);
free(cdata); free(cdata);
} }

View File

@@ -52,6 +52,8 @@ const struct cmd_entry cmd_confirm_before_entry = {
struct cmd_confirm_before_data { struct cmd_confirm_before_data {
struct cmdq_item *item; struct cmdq_item *item;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
char *file;
int parse_flags;
u_char confirm_key; u_char confirm_key;
int default_yes; int default_yes;
}; };
@@ -71,7 +73,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
struct client *tc = cmdq_get_target_client(item); struct client *tc = cmdq_get_target_client(item);
struct cmd_find_state *target = cmdq_get_target(item); struct cmd_find_state *target = cmdq_get_target(item);
char *new_prompt, *cause = NULL; char *new_prompt, *cause = NULL;
const char *confirm_key, *prompt, *cmd; const char *confirm_key, *prompt, *cmd, *file;
int wait = !args_has(args, 'b'), n; int wait = !args_has(args, 'b'), n;
cdata = xcalloc(1, sizeof *cdata); cdata = xcalloc(1, sizeof *cdata);
@@ -82,6 +84,10 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
free(cdata); free(cdata);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
cmd_get_source(self, &file, NULL);
if (file != NULL)
cdata->file = xstrdup(file);
cdata->parse_flags = cmd_get_parse_flags(self);
if (wait) if (wait)
cdata->item = item; cdata->item = item;
@@ -127,6 +133,8 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
{ {
struct cmd_confirm_before_data *cdata = data; struct cmd_confirm_before_data *cdata = data;
struct cmdq_item *item = cdata->item, *new_item; struct cmdq_item *item = cdata->item, *new_item;
struct cmdq_state *cs;
struct cmd_invoke_input ci = { 0 };
int retcode = 1; int retcode = 1;
if (c->flags & CLIENT_DEAD) if (c->flags & CLIENT_DEAD)
@@ -138,12 +146,14 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
goto out; goto out;
retcode = 0; retcode = 0;
ci.file = cdata->file;
ci.flags = cdata->parse_flags;
if (item == NULL) { if (item == NULL) {
new_item = cmd_invoke_get(cdata->tree, NULL, NULL); new_item = cmd_invoke_get(cdata->tree, NULL, &ci);
cmdq_append(c, new_item); cmdq_append(c, new_item);
} else { } else {
new_item = cmd_invoke_get(cdata->tree, cmdq_get_state(item), cs = cmdq_get_state(item);
NULL); new_item = cmd_invoke_get(cdata->tree, cs, &ci);
cmdq_insert_after(item, new_item); cmdq_insert_after(item, new_item);
} }
@@ -163,5 +173,6 @@ cmd_confirm_before_free(void *data)
struct cmd_confirm_before_data *cdata = data; struct cmd_confirm_before_data *cdata = data;
cmd_parse_free(cdata->tree); cmd_parse_free(cdata->tree);
free(cdata->file);
free(cdata); free(cdata);
} }

View File

@@ -46,6 +46,8 @@ const struct cmd_entry cmd_display_panes_entry = {
struct cmd_display_panes_data { struct cmd_display_panes_data {
struct cmdq_item *item; struct cmdq_item *item;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
char *file;
int parse_flags;
}; };
struct cmd_display_panes_ctx { struct cmd_display_panes_ctx {
@@ -298,6 +300,7 @@ cmd_display_panes_free(__unused struct client *c, void *data)
if (cdata->item != NULL) if (cdata->item != NULL)
cmdq_continue(cdata->item); cmdq_continue(cdata->item);
cmd_parse_free(cdata->tree); cmd_parse_free(cdata->tree);
free(cdata->file);
free(cdata); free(cdata);
} }
@@ -333,6 +336,8 @@ cmd_display_panes_key(struct client *c, void *data, struct key_event *event)
xasprintf(&expanded, "%%%u", wp->id); xasprintf(&expanded, "%%%u", wp->id);
ci.argc = 1; ci.argc = 1;
ci.argv = &expanded; ci.argv = &expanded;
ci.file = cdata->file;
ci.flags = cdata->parse_flags;
if (item != NULL) if (item != NULL)
cs = cmdq_get_state(item); cs = cmdq_get_state(item);
@@ -354,6 +359,7 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = tc->session; struct session *s = tc->session;
u_int delay; u_int delay;
char *cause; char *cause;
const char *file;
struct cmd_display_panes_data *cdata; struct cmd_display_panes_data *cdata;
int wait = !args_has(args, 'b'); int wait = !args_has(args, 'b');
@@ -382,6 +388,10 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
free(cdata); free(cdata);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
cmd_get_source(self, &file, NULL);
if (file != NULL)
cdata->file = xstrdup(file);
cdata->parse_flags = cmd_get_parse_flags(self);
if (args_has(args, 'N')) { if (args_has(args, 'N')) {
server_client_set_overlay(tc, delay, NULL, NULL, server_client_set_overlay(tc, delay, NULL, NULL,

View File

@@ -56,6 +56,9 @@ struct cmd_if_shell_data {
struct cmd_parse_tree *cmd_if; struct cmd_parse_tree *cmd_if;
struct cmd_parse_tree *cmd_else; struct cmd_parse_tree *cmd_else;
char *file;
int parse_flags;
struct client *client; struct client *client;
struct cmdq_item *item; struct cmdq_item *item;
}; };
@@ -77,6 +80,8 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
struct cmd_if_shell_data *cdata; struct cmd_if_shell_data *cdata;
struct cmdq_item *new_item; struct cmdq_item *new_item;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
struct cmd_invoke_input input = { 0 };
const char *file;
char *shellcmd, *cause = NULL; char *shellcmd, *cause = NULL;
struct client *tc = cmdq_get_target_client(item); struct client *tc = cmdq_get_target_client(item);
struct session *s = target->s; struct session *s = target->s;
@@ -101,7 +106,10 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
free(cause); free(cause);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
new_item = cmd_invoke_get(tree, cmdq_get_state(item), NULL); cmd_get_source(self, &file, NULL);
input.file = file;
input.flags = cmd_get_parse_flags(self);
new_item = cmd_invoke_get(tree, cmdq_get_state(item), &input);
cmd_parse_free(tree); cmd_parse_free(tree);
cmdq_insert_after(item, new_item); cmdq_insert_after(item, new_item);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
@@ -121,6 +129,10 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
goto fail; goto fail;
} }
} }
cmd_get_source(self, &file, NULL);
if (file != NULL)
cdata->file = xstrdup(file);
cdata->parse_flags = cmd_get_parse_flags(self);
if (!wait) if (!wait)
cdata->client = tc; cdata->client = tc;
@@ -158,6 +170,7 @@ cmd_if_shell_callback(struct job *job)
struct client *c = cdata->client; struct client *c = cdata->client;
struct cmdq_item *item = cdata->item, *new_item; struct cmdq_item *item = cdata->item, *new_item;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
struct cmd_invoke_input input = { 0 };
int status; int status;
status = job_get_status(job); status = job_get_status(job);
@@ -168,11 +181,13 @@ cmd_if_shell_callback(struct job *job)
if (tree == NULL) if (tree == NULL)
goto out; goto out;
input.file = cdata->file;
input.flags = cdata->parse_flags;
if (item == NULL) { if (item == NULL) {
new_item = cmd_invoke_get(tree, NULL, NULL); new_item = cmd_invoke_get(tree, NULL, &input);
cmdq_append(c, new_item); cmdq_append(c, new_item);
} else { } else {
new_item = cmd_invoke_get(tree, cmdq_get_state(item), NULL); new_item = cmd_invoke_get(tree, cmdq_get_state(item), &input);
cmdq_insert_after(item, new_item); cmdq_insert_after(item, new_item);
} }
@@ -193,5 +208,6 @@ cmd_if_shell_free(void *data)
cmd_parse_free(cdata->cmd_else); cmd_parse_free(cdata->cmd_else);
if (cdata->cmd_if != NULL) if (cdata->cmd_if != NULL)
cmd_parse_free(cdata->cmd_if); cmd_parse_free(cdata->cmd_if);
free(cdata->file);
free(cdata); free(cdata);
} }

View File

@@ -58,6 +58,8 @@ struct cmd_run_shell_data {
struct client *client; struct client *client;
char *cmd; char *cmd;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
char *file;
int parse_flags;
char *cwd; char *cwd;
struct cmdq_item *item; struct cmdq_item *item;
struct session *s; struct session *s;
@@ -114,7 +116,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
struct client *tc = cmdq_get_target_client(item); struct client *tc = cmdq_get_target_client(item);
struct session *s = target->s; struct session *s = target->s;
struct window_pane *wp = target->wp; struct window_pane *wp = target->wp;
const char *delay, *cmd; const char *delay, *cmd, *file;
struct format_tree *ft; struct format_tree *ft;
double d; double d;
struct timeval tv; struct timeval tv;
@@ -153,6 +155,10 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
cmd_run_shell_free(cdata); cmd_run_shell_free(cdata);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
cmd_get_source(self, &file, NULL);
if (file != NULL)
cdata->file = xstrdup(file);
cdata->parse_flags = cmd_get_parse_flags(self);
} }
if (args_has(args, 't') && wp != NULL) if (args_has(args, 't') && wp != NULL)
@@ -206,6 +212,7 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg)
const char *cmd = cdata->cmd; const char *cmd = cdata->cmd;
struct cmdq_item *item = cdata->item, *new_item; struct cmdq_item *item = cdata->item, *new_item;
struct cmdq_state *cs = NULL; struct cmdq_state *cs = NULL;
struct cmd_invoke_input input = { 0 };
if (cdata->tree == NULL) { if (cdata->tree == NULL) {
if (cmd == NULL) { if (cmd == NULL) {
@@ -232,7 +239,9 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg)
if (item != NULL) if (item != NULL)
cs = cmdq_get_state(item); cs = cmdq_get_state(item);
new_item = cmd_invoke_get(cdata->tree, cs, NULL); input.file = cdata->file;
input.flags = cdata->parse_flags;
new_item = cmd_invoke_get(cdata->tree, cs, &input);
if (item == NULL) if (item == NULL)
cmdq_append(c, new_item); cmdq_append(c, new_item);
else else
@@ -305,6 +314,7 @@ cmd_run_shell_free(void *data)
if (cdata->client != NULL) if (cdata->client != NULL)
server_client_unref(cdata->client); server_client_unref(cdata->client);
cmd_parse_free(cdata->tree); cmd_parse_free(cdata->tree);
free(cdata->file);
free(cdata->cwd); free(cdata->cwd);
free(cdata->cmd); free(cdata->cmd);
free(cdata); free(cdata);