summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2011-12-09 16:28:18 +0000
committernicm <nicm@openbsd.org>2011-12-09 16:28:18 +0000
commit23f1d67dc61e9203c2156a60f0b3eae1547c0ef3 (patch)
treee98d87a03b19af9eaf1ac39abbcb164d0200df46 /usr.bin/tmux/cmd.c
parentAdd new KERN_PROC_CWD sysctl to get the current working directory of a process. (diff)
downloadwireguard-openbsd-23f1d67dc61e9203c2156a60f0b3eae1547c0ef3.tar.xz
wireguard-openbsd-23f1d67dc61e9203c2156a60f0b3eae1547c0ef3.zip
Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise: 1) If tmux neww is run from the command line, the working directory of the client is used. 2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current working directory of the process in the active pane. 3) If that fails, the directory where the session was created is used. Support code by Romain Francois, OpenBSD specific bits by me. Note this requires a recent userland and kernel with KERN_PROC_CWD.
Diffstat (limited to 'usr.bin/tmux/cmd.c')
-rw-r--r--usr.bin/tmux/cmd.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c
index f5699e4ed2b..f322c8d23f5 100644
--- a/usr.bin/tmux/cmd.c
+++ b/usr.bin/tmux/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.56 2011/06/05 11:19:03 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.57 2011/12/09 16:28:18 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1213,3 +1213,28 @@ cmd_template_replace(char *template, const char *s, int idx)
return (buf);
}
+
+/* Return the default path for a new pane. */
+char *
+cmd_get_default_path(struct cmd_ctx *ctx)
+{
+ char *cwd;
+ struct session *s;
+ struct window_pane *wp;
+
+ if ((s = cmd_current_session(ctx, 0)) == NULL)
+ return (NULL);
+
+ cwd = options_get_string(&s->options, "default-path");
+ if (*cwd == '\0') {
+ if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
+ return (ctx->cmdclient->cwd);
+ if (ctx->curclient != NULL) {
+ wp = s->curw->window->active;
+ if ((cwd = get_proc_cwd(wp->pid)) != NULL)
+ return (cwd);
+ }
+ return (s->cwd);
+ }
+ return (cwd);
+}