summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2018-05-24 09:42:49 +0000
committernicm <nicm>2018-05-24 09:42:49 +0000
commitb9a6162d2f9bea63c3ad421e9c3969eea2852b00 (patch)
treed944f370a3a21ea175f9fe958f9773146cdbfc1a
parent8f5903d7c3d75763ed5dc37ff49a39fe3b3b7831 (diff)
Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub issue 1331.
-rw-r--r--cmd-if-shell.c12
-rw-r--r--cmd-new-session.c4
-rw-r--r--cmd-new-window.c4
-rw-r--r--cmd-run-shell.c12
-rw-r--r--cmd-source-file.c2
-rw-r--r--cmd-split-window.c4
-rw-r--r--server-client.c12
-rw-r--r--tmux.h2
-rw-r--r--window.c3
9 files changed, 19 insertions, 36 deletions
diff --git a/cmd-if-shell.c b/cmd-if-shell.c
index 304fe910..d7ce3039 100644
--- a/cmd-if-shell.c
+++ b/cmd-if-shell.c
@@ -73,14 +73,6 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct window_pane *wp = item->target.wp;
- const char *cwd;
-
- if (item->client != NULL && item->client->session == NULL)
- cwd = item->client->cwd;
- else if (s != NULL)
- cwd = s->cwd;
- else
- cwd = NULL;
shellcmd = format_single(item, args->argv[0], c, s, wl, wp);
if (args_has(args, 'F')) {
@@ -128,8 +120,8 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
cdata->item = NULL;
memcpy(&cdata->mouse, &shared->mouse, sizeof cdata->mouse);
- job_run(shellcmd, s, cwd, NULL, cmd_if_shell_callback,
- cmd_if_shell_free, cdata, 0);
+ job_run(shellcmd, s, server_client_get_cwd(item->client, s), NULL,
+ cmd_if_shell_callback, cmd_if_shell_free, cdata, 0);
free(shellcmd);
if (args_has(args, 'b'))
diff --git a/cmd-new-session.c b/cmd-new-session.c
index 26cb08ba..7af67a11 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -156,10 +156,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
/* Get the new session working directory. */
if ((tmp = args_get(args, 'c')) != NULL)
cwd = format_single(item, tmp, c, NULL, NULL, NULL);
- else if (c != NULL && c->session == NULL && c->cwd != NULL)
- cwd = xstrdup(c->cwd);
else
- cwd = xstrdup(".");
+ cwd = xstrdup(server_client_get_cwd(c, NULL));
/*
* If this is a new client, check for nesting and save the termios
diff --git a/cmd-new-window.c b/cmd-new-window.c
index 6517e99e..6a7cf0b8 100644
--- a/cmd-new-window.c
+++ b/cmd-new-window.c
@@ -95,10 +95,8 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
if ((tmp = args_get(args, 'c')) != NULL)
cwd = format_single(item, tmp, c, s, NULL, NULL);
- else if (item->client != NULL && item->client->session == NULL)
- cwd = xstrdup(item->client->cwd);
else
- cwd = xstrdup(s->cwd);
+ cwd = xstrdup(server_client_get_cwd(item->client, s));
if ((tmp = args_get(args, 'n')) != NULL)
name = format_single(item, tmp, c, s, NULL, NULL);
diff --git a/cmd-run-shell.c b/cmd-run-shell.c
index 8de8736a..a9961988 100644
--- a/cmd-run-shell.c
+++ b/cmd-run-shell.c
@@ -90,14 +90,6 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct window_pane *wp = item->target.wp;
- const char *cwd;
-
- if (item->client != NULL && item->client->session == NULL)
- cwd = item->client->cwd;
- else if (s != NULL)
- cwd = s->cwd;
- else
- cwd = NULL;
cdata = xcalloc(1, sizeof *cdata);
cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp);
@@ -110,8 +102,8 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
if (!args_has(args, 'b'))
cdata->item = item;
- job_run(cdata->cmd, s, cwd, NULL, cmd_run_shell_callback,
- cmd_run_shell_free, cdata, 0);
+ job_run(cdata->cmd, s, server_client_get_cwd(item->client, s), NULL,
+ cmd_run_shell_callback, cmd_run_shell_free, cdata, 0);
if (args_has(args, 'b'))
return (CMD_RETURN_NORMAL);
diff --git a/cmd-source-file.c b/cmd-source-file.c
index 0328089f..ffb7f423 100644
--- a/cmd-source-file.c
+++ b/cmd-source-file.c
@@ -61,7 +61,7 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
if (*path == '/')
pattern = xstrdup(path);
else {
- utf8_stravis(&tmp, server_client_get_cwd(c), VIS_GLOB);
+ utf8_stravis(&tmp, server_client_get_cwd(c, NULL), VIS_GLOB);
xasprintf(&pattern, "%s/%s", tmp, path);
free(tmp);
}
diff --git a/cmd-split-window.c b/cmd-split-window.c
index ab7f9bc5..7b58f81f 100644
--- a/cmd-split-window.c
+++ b/cmd-split-window.c
@@ -88,10 +88,8 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
if ((tmp = args_get(args, 'c')) != NULL)
cwd = format_single(item, tmp, c, s, NULL, NULL);
- else if (item->client != NULL && item->client->session == NULL)
- cwd = xstrdup(item->client->cwd);
else
- cwd = xstrdup(s->cwd);
+ cwd = xstrdup(server_client_get_cwd(item->client, s));
type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'h'))
diff --git a/server-client.c b/server-client.c
index 4da9f08a..6a94bb56 100644
--- a/server-client.c
+++ b/server-client.c
@@ -1847,15 +1847,19 @@ server_client_add_message(struct client *c, const char *fmt, ...)
/* Get client working directory. */
const char *
-server_client_get_cwd(struct client *c)
+server_client_get_cwd(struct client *c, struct session *s)
{
- struct session *s;
+ const char *home;
if (c != NULL && c->session == NULL && c->cwd != NULL)
return (c->cwd);
+ if (s != NULL && s->cwd != NULL)
+ return (s->cwd);
if (c != NULL && (s = c->session) != NULL && s->cwd != NULL)
return (s->cwd);
- return (".");
+ if ((home = find_home()) != NULL)
+ return (home);
+ return ("/");
}
/* Resolve an absolute path or relative to client working directory. */
@@ -1867,7 +1871,7 @@ server_client_get_path(struct client *c, const char *file)
if (*file == '/')
path = xstrdup(file);
else
- xasprintf(&path, "%s/%s", server_client_get_cwd(c), file);
+ xasprintf(&path, "%s/%s", server_client_get_cwd(c, NULL), file);
if (realpath(path, resolved) == NULL)
return (path);
free(path);
diff --git a/tmux.h b/tmux.h
index d66b19d7..d46dca2e 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1906,7 +1906,7 @@ void server_client_push_stderr(struct client *);
void printflike(2, 3) server_client_add_message(struct client *, const char *,
...);
char *server_client_get_path(struct client *, const char *);
-const char *server_client_get_cwd(struct client *);
+const char *server_client_get_cwd(struct client *, struct session *);
/* server-fn.c */
void server_redraw_client(struct client *);
diff --git a/window.c b/window.c
index 79a5b30c..3b9469fe 100644
--- a/window.c
+++ b/window.c
@@ -918,7 +918,8 @@ window_pane_spawn(struct window_pane *wp, int argc, char **argv,
cmd = cmd_stringify_argv(wp->argc, wp->argv);
log_debug("%s: shell=%s", __func__, wp->shell);
- log_debug("%s: command=%s", __func__, cmd);
+ log_debug("%s: cmd=%s", __func__, cmd);
+ log_debug("%s: cwd=%s", __func__, cwd);
for (i = 0; i < wp->argc; i++)
log_debug("%s: argv[%d]=%s", __func__, i, wp->argv[i]);
environ_log(env, "%s: environment ", __func__);