mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-07 16:54:01 +01:00
Set working directory for run-shell and if-shell.
This commit is contained in:
parent
5a2d0533a8
commit
583b4ab72b
@ -66,16 +66,24 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
struct winlink *wl = NULL;
|
||||
struct window_pane *wp = NULL;
|
||||
struct format_tree *ft;
|
||||
int cwd;
|
||||
|
||||
if (args_has(args, 't'))
|
||||
if (args_has(args, 't')) {
|
||||
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
|
||||
else {
|
||||
cwd = wp->cwd;
|
||||
} else {
|
||||
c = cmd_find_client(cmdq, NULL, 1);
|
||||
if (c != NULL && c->session != NULL) {
|
||||
s = c->session;
|
||||
wl = s->curw;
|
||||
wp = wl->window->active;
|
||||
}
|
||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
cwd = cmdq->client->cwd;
|
||||
else if (s != NULL)
|
||||
cwd = s->cwd;
|
||||
else
|
||||
cwd = -1;
|
||||
}
|
||||
|
||||
ft = format_create();
|
||||
@ -118,7 +126,8 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
cmdq->references++;
|
||||
|
||||
cdata->references = 1;
|
||||
job_run(shellcmd, s, cmd_if_shell_callback, cmd_if_shell_free, cdata);
|
||||
job_run(shellcmd, s, cwd, cmd_if_shell_callback, cmd_if_shell_free,
|
||||
cdata);
|
||||
free(shellcmd);
|
||||
|
||||
if (cdata->bflag)
|
||||
|
@ -80,16 +80,24 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
struct winlink *wl = NULL;
|
||||
struct window_pane *wp = NULL;
|
||||
struct format_tree *ft;
|
||||
int cwd;
|
||||
|
||||
if (args_has(args, 't'))
|
||||
if (args_has(args, 't')) {
|
||||
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
|
||||
else {
|
||||
cwd = wp->cwd;
|
||||
} else {
|
||||
c = cmd_find_client(cmdq, NULL, 1);
|
||||
if (c != NULL && c->session != NULL) {
|
||||
s = c->session;
|
||||
wl = s->curw;
|
||||
wp = wl->window->active;
|
||||
}
|
||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
cwd = cmdq->client->cwd;
|
||||
else if (s != NULL)
|
||||
cwd = s->cwd;
|
||||
else
|
||||
cwd = -1;
|
||||
}
|
||||
|
||||
ft = format_create();
|
||||
@ -105,7 +113,8 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
cdata->cmdq = cmdq;
|
||||
cmdq->references++;
|
||||
|
||||
job_run(shellcmd, s, cmd_run_shell_callback, cmd_run_shell_free, cdata);
|
||||
job_run(shellcmd, s, cwd, cmd_run_shell_callback, cmd_run_shell_free,
|
||||
cdata);
|
||||
|
||||
if (cdata->bflag)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
5
job.c
5
job.c
@ -41,7 +41,7 @@ struct joblist all_jobs = LIST_HEAD_INITIALIZER(all_jobs);
|
||||
|
||||
/* Start a job running, if it isn't already. */
|
||||
struct job *
|
||||
job_run(const char *cmd, struct session *s,
|
||||
job_run(const char *cmd, struct session *s, int cwd,
|
||||
void (*callbackfn)(struct job *), void (*freefn)(void *), void *data)
|
||||
{
|
||||
struct job *job;
|
||||
@ -67,6 +67,9 @@ job_run(const char *cmd, struct session *s,
|
||||
case 0: /* child */
|
||||
clear_signals(1);
|
||||
|
||||
if (cwd != -1 && fchdir(cwd) != 0)
|
||||
chdir("/");
|
||||
|
||||
environ_push(&env);
|
||||
environ_free(&env);
|
||||
|
||||
|
2
status.c
2
status.c
@ -515,7 +515,7 @@ status_find_job(struct client *c, char **iptr)
|
||||
|
||||
/* If not found at all, start the job and add to the tree. */
|
||||
if (so == NULL) {
|
||||
job_run(cmd, NULL, status_job_callback, status_job_free, c);
|
||||
job_run(cmd, NULL, -1, status_job_callback, status_job_free, c);
|
||||
c->references++;
|
||||
|
||||
so = xmalloc(sizeof *so);
|
||||
|
2
tmux.h
2
tmux.h
@ -1613,7 +1613,7 @@ int options_table_find(const char *, const struct options_table_entry **,
|
||||
|
||||
/* job.c */
|
||||
extern struct joblist all_jobs;
|
||||
struct job *job_run(const char *, struct session *,
|
||||
struct job *job_run(const char *, struct session *, int,
|
||||
void (*)(struct job *), void (*)(void *), void *);
|
||||
void job_free(struct job *);
|
||||
void job_died(struct job *, int);
|
||||
|
@ -1465,7 +1465,7 @@ window_copy_copy_pipe(struct window_pane *wp, struct session *sess,
|
||||
format_defaults(ft, NULL, sess, NULL, wp);
|
||||
expanded = format_expand(ft, arg);
|
||||
|
||||
job = job_run(expanded, sess, NULL, NULL, NULL);
|
||||
job = job_run(expanded, sess, -1, NULL, NULL, NULL);
|
||||
bufferevent_write(job->event, buf, len);
|
||||
|
||||
free(expanded);
|
||||
|
Loading…
Reference in New Issue
Block a user