-/* $OpenBSD: cmd-if-shell.c,v 1.31 2015/04/21 21:31:02 nicm Exp $ */
+/* $OpenBSD: cmd-if-shell.c,v 1.32 2015/04/24 22:19:36 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
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();
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)
-/* $OpenBSD: cmd-run-shell.c,v 1.27 2015/02/05 10:29:43 nicm Exp $ */
+/* $OpenBSD: cmd-run-shell.c,v 1.28 2015/04/24 22:19:36 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
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();
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);
-/* $OpenBSD: job.c,v 1.34 2014/10/20 23:27:14 nicm Exp $ */
+/* $OpenBSD: job.c,v 1.35 2015/04/24 22:19:36 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
/* 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;
case 0: /* child */
clear_signals(1);
+ if (cwd != -1 && fchdir(cwd) != 0)
+ chdir("/");
+
environ_push(&env);
environ_free(&env);
-/* $OpenBSD: status.c,v 1.125 2015/04/19 21:34:21 nicm Exp $ */
+/* $OpenBSD: status.c,v 1.126 2015/04/24 22:19:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
/* 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);
-/* $OpenBSD: tmux.h,v 1.497 2015/04/22 15:32:33 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.498 2015/04/24 22:19:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
/* 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);
-/* $OpenBSD: window-copy.c,v 1.129 2015/04/21 15:16:06 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.130 2015/04/24 22:19:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
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);