From d17c90583a2cbbb15ec1a357380b0985e6472a5f Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 1 Jan 2018 11:19:08 +0000 Subject: Prefer PWD for current directory if present in client, from Wei Zhao in GitHub issue 1183. --- tmux.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tmux.c') diff --git a/tmux.c b/tmux.c index b8a73fd9..b8ecfecc 100644 --- a/tmux.c +++ b/tmux.c @@ -193,7 +193,7 @@ main(int argc, char **argv) { char *path, *label, **var; char tmp[PATH_MAX]; - const char *s, *shell; + const char *s, *shell, *cwd; int opt, flags, keys; const struct options_table_entry *oe; @@ -294,8 +294,9 @@ main(int argc, char **argv) global_environ = environ_create(); for (var = environ; *var != NULL; var++) environ_put(global_environ, *var); - if (getcwd(tmp, sizeof tmp) != NULL) - environ_set(global_environ, "PWD", "%s", tmp); + if ((cwd = getenv("PWD")) == NULL && + (cwd = getcwd(tmp, sizeof tmp)) != NULL) + environ_set(global_environ, "PWD", "%s", cwd); global_options = options_create(NULL); global_s_options = options_create(NULL); -- cgit