Add -c to run-shell to set working directory, from someone in GitHub

issue 3661.
pull/3673/head
nicm 2023-08-23 08:40:25 +00:00
parent 52084b2948
commit 71d453f169
2 changed files with 14 additions and 5 deletions

View File

@ -44,8 +44,9 @@ const struct cmd_entry cmd_run_shell_entry = {
.name = "run-shell", .name = "run-shell",
.alias = "run", .alias = "run",
.args = { "bd:Ct:", 0, 1, cmd_run_shell_args_parse }, .args = { "bd:Ct:c:", 0, 2, cmd_run_shell_args_parse },
.usage = "[-bC] [-d delay] " CMD_TARGET_PANE_USAGE " [shell-command]", .usage = "[-bC] [-c start-directory] [-d delay] " CMD_TARGET_PANE_USAGE
" [shell-command]",
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL }, .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
@ -103,6 +104,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
struct args *args = cmd_get_args(self); struct args *args = cmd_get_args(self);
struct cmd_find_state *target = cmdq_get_target(item); struct cmd_find_state *target = cmdq_get_target(item);
struct cmd_run_shell_data *cdata; struct cmd_run_shell_data *cdata;
struct client *c = cmdq_get_client(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;
@ -137,7 +139,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
cdata->wp_id = -1; cdata->wp_id = -1;
if (wait) { if (wait) {
cdata->client = cmdq_get_client(item); cdata->client = c;
cdata->item = item; cdata->item = item;
} else { } else {
cdata->client = tc; cdata->client = tc;
@ -145,8 +147,10 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
} }
if (cdata->client != NULL) if (cdata->client != NULL)
cdata->client->references++; cdata->client->references++;
if (args_has(args, 'c'))
cdata->cwd = xstrdup(server_client_get_cwd(cmdq_get_client(item), s)); cdata->cwd = xstrdup(args_get(args, 'c'));
else
cdata->cwd = xstrdup(server_client_get_cwd(c, s));
cdata->s = s; cdata->s = s;
if (s != NULL) if (s != NULL)

5
tmux.1
View File

@ -6639,6 +6639,7 @@ option.
.Tg run .Tg run
.It Xo Ic run-shell .It Xo Ic run-shell
.Op Fl bC .Op Fl bC
.Op Fl c Ar start-directory
.Op Fl d Ar delay .Op Fl d Ar delay
.Op Fl t Ar target-pane .Op Fl t Ar target-pane
.Op Ar shell-command .Op Ar shell-command
@ -6666,6 +6667,10 @@ waits for
.Ar delay .Ar delay
seconds before starting the command. seconds before starting the command.
If If
.Fl c
is given, the current working directory is set to
.Ar start-directory .
If
.Fl C .Fl C
is not given, any output to stdout is displayed in view mode (in the pane is not given, any output to stdout is displayed in view mode (in the pane
specified by specified by