Allow run-shell arguments after a shell command to be expanded as #1, #2

and so on. From Rasmus Thystrup Karstensen in GitHub issue 5121.
This commit is contained in:
nicm
2026-06-01 08:27:37 +00:00
parent a9721ea268
commit 3bff7a9e62
3 changed files with 37 additions and 7 deletions

View File

@@ -44,9 +44,9 @@ const struct cmd_entry cmd_run_shell_entry = {
.name = "run-shell",
.alias = "run",
.args = { "bd:Ct:Es:c:", 0, 1, cmd_run_shell_args_parse },
.args = { "bd:Ct:Es:c:", 0, -1, cmd_run_shell_args_parse },
.usage = "[-bCE] [-c start-directory] [-d delay] " CMD_TARGET_PANE_USAGE
" [shell-command]",
" [shell-command [argument ...]]",
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
@@ -115,9 +115,11 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = target->s;
struct window_pane *wp = target->wp;
const char *delay, *cmd;
struct format_tree *ft;
double d;
struct timeval tv;
char *end;
char *end, key[16];
u_int i;
int wait = !args_has(args, 'b');
if ((delay = args_get(args, 'd')) != NULL) {
@@ -132,8 +134,15 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
cdata = xcalloc(1, sizeof *cdata);
if (!args_has(args, 'C')) {
cmd = args_string(args, 0);
if (cmd != NULL)
cdata->cmd = format_single_from_target(item, cmd);
if (cmd != NULL) {
ft = format_create_from_target(item);
for (i = 1; i < args_count(args); i++) {
xsnprintf(key, sizeof key, "%u", i);
format_add(ft, key, "%s", args_string(args, i));
}
cdata->cmd = format_expand(ft, cmd);
format_free(ft);
}
} else {
cdata->state = args_make_commands_prepare(self, item, 0, NULL,
wait, 1);