summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/tmux/cmd-new-session.c18
-rw-r--r--usr.bin/tmux/cmd-new-window.c13
-rw-r--r--usr.bin/tmux/cmd-split-window.c13
-rw-r--r--usr.bin/tmux/session.c5
-rw-r--r--usr.bin/tmux/tmux.15
-rw-r--r--usr.bin/tmux/tmux.c14
-rw-r--r--usr.bin/tmux/tmux.h3
7 files changed, 41 insertions, 30 deletions
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c
index cae1afdd0c8..cce9c8d0dec 100644
--- a/usr.bin/tmux/cmd-new-session.c
+++ b/usr.bin/tmux/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-session.c,v 1.29 2010/04/06 21:35:44 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.30 2010/06/27 02:56:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,8 +18,10 @@
#include <sys/types.h>
+#include <pwd.h>
#include <string.h>
#include <termios.h>
+#include <unistd.h>
#include "tmux.h"
@@ -125,8 +127,9 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
struct window_pane *wp;
struct environ env;
struct termios tio, *tiop;
- const char *update;
- char *overrides, *cmd, *cwd, *cause;
+ struct passwd *pw;
+ const char *update, *cwd;
+ char *overrides, *cmd, *cause;
int detached, idx;
u_int sx, sy, i;
@@ -198,8 +201,13 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
/* Get the new session working directory. */
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
cwd = ctx->cmdclient->cwd;
- else
- cwd = options_get_string(&global_s_options, "default-path");
+ else {
+ pw = getpwuid(getuid());
+ if (pw->pw_dir != NULL && *pw->pw_dir != '\0')
+ cwd = pw->pw_dir;
+ else
+ cwd = "/";
+ }
/* Find new session size. */
if (detached) {
diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c
index c1728b2e84e..bf17196cbda 100644
--- a/usr.bin/tmux/cmd-new-window.c
+++ b/usr.bin/tmux/cmd-new-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-window.c,v 1.14 2010/06/21 01:27:46 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.15 2010/06/27 02:56:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -176,10 +176,13 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd = data->cmd;
if (cmd == NULL)
cmd = options_get_string(&s->options, "default-command");
- if (ctx->cmdclient == NULL || ctx->cmdclient->cwd == NULL)
- cwd = options_get_string(&s->options, "default-path");
- else
- cwd = ctx->cmdclient->cwd;
+ cwd = options_get_string(&s->options, "default-path");
+ if (*cwd == '\0') {
+ if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
+ cwd = ctx->cmdclient->cwd;
+ else
+ cwd = s->cwd;
+ }
if (idx == -1)
idx = -1 - options_get_number(&s->options, "base-index");
diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c
index bcd3424582c..b680454cef1 100644
--- a/usr.bin/tmux/cmd-split-window.c
+++ b/usr.bin/tmux/cmd-split-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-split-window.c,v 1.19 2010/01/07 20:52:18 nicm Exp $ */
+/* $OpenBSD: cmd-split-window.c,v 1.20 2010/06/27 02:56:59 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -170,10 +170,13 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd = data->cmd;
if (cmd == NULL)
cmd = options_get_string(&s->options, "default-command");
- if (ctx->cmdclient == NULL || ctx->cmdclient->cwd == NULL)
- cwd = options_get_string(&s->options, "default-path");
- else
- cwd = ctx->cmdclient->cwd;
+ cwd = options_get_string(&s->options, "default-path");
+ if (*cwd == '\0') {
+ if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
+ cwd = ctx->cmdclient->cwd;
+ else
+ cwd = s->cwd;
+ }
type = LAYOUT_TOPBOTTOM;
if (data->flag_horizontal)
diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c
index 79c83881dd5..558e03f773e 100644
--- a/usr.bin/tmux/session.c
+++ b/usr.bin/tmux/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.18 2010/06/21 01:27:46 nicm Exp $ */
+/* $OpenBSD: session.c,v 1.19 2010/06/27 02:56:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -68,6 +68,8 @@ session_create(const char *name, const char *cmd, const char *cwd,
fatal("gettimeofday failed");
memcpy(&s->activity_time, &s->creation_time, sizeof s->activity_time);
+ s->cwd = xstrdup(cwd);
+
s->curw = NULL;
TAILQ_INIT(&s->lastw);
RB_INIT(&s->windows);
@@ -142,6 +144,7 @@ session_destroy(struct session *s)
while (!RB_EMPTY(&s->windows))
winlink_remove(&s->windows, RB_ROOT(&s->windows));
+ xfree(s->cwd);
xfree(s->name);
for (i = 0; i < ARRAY_LENGTH(&dead_sessions); i++) {
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 45a8104b684..5e5bd901103 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.179 2010/06/27 00:22:22 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.180 2010/06/27 02:56:59 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -1626,7 +1626,8 @@ is used as a login shell.
.It Ic default-path Ar path
Set the default working directory for processes created from keys, or
interactively from the prompt.
-The default is the current working directory when the server is started.
+The default is empty, which means to use the working directory of the shell
+from which the server was started if it is available or the user's home if not.
.It Ic default-terminal Ar terminal
Set the default terminal for new windows created in this session - the
default value of the
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index bdddc047111..c72be02927b 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.81 2010/06/27 00:22:22 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.82 2010/06/27 02:56:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -239,7 +239,7 @@ main(int argc, char **argv)
struct env_data envdata;
struct msg_command_data cmddata;
char *s, *shellcmd, *path, *label, *home, *cause;
- char cwd[MAXPATHLEN], **var;
+ char **var;
void *buf;
size_t len;
int opt, flags, quiet = 0, cmdflags = 0;
@@ -339,6 +339,7 @@ main(int argc, char **argv)
options_set_number(so, "bell-action", BELL_ANY);
options_set_number(so, "buffer-limit", 9);
options_set_string(so, "default-command", "%s", "");
+ options_set_string(so, "default-path", "%s", "");
options_set_string(so, "default-shell", "%s", getshell());
options_set_string(so, "default-terminal", "screen");
options_set_number(so, "detach-on-destroy", 1);
@@ -435,15 +436,6 @@ main(int argc, char **argv)
options_set_number(wo, "utf8", 0);
}
- if (getcwd(cwd, sizeof cwd) == NULL) {
- pw = getpwuid(getuid());
- if (pw->pw_dir != NULL && *pw->pw_dir != '\0')
- strlcpy(cwd, pw->pw_dir, sizeof cwd);
- else
- strlcpy(cwd, "/", sizeof cwd);
- }
- options_set_string(so, "default-path", "%s", cwd);
-
if (cfg_file == NULL) {
home = getenv("HOME");
if (home == NULL || *home == '\0') {
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index d10baf752f9..0767b4acf6d 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.229 2010/06/26 18:20:53 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.230 2010/06/27 02:56:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -926,6 +926,7 @@ TAILQ_HEAD(session_groups, session_group);
struct session {
char *name;
+ char *cwd;
struct timeval creation_time;
struct timeval activity_time;