summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2013-10-10 12:07:36 +0000
committernicm <nicm@openbsd.org>2013-10-10 12:07:36 +0000
commit8a403d25b146c7f476f4429cf37fd6dbb747c66e (patch)
tree523204c719648ca2335fa6aa3781bdfa7d587d38
parentMake cmdq->client_exit a tristate (-1 means "not set") so that if (diff)
downloadwireguard-openbsd-8a403d25b146c7f476f4429cf37fd6dbb747c66e.tar.xz
wireguard-openbsd-8a403d25b146c7f476f4429cf37fd6dbb747c66e.zip
Support -c for new-session, based on code from J Raynor.
-rw-r--r--usr.bin/tmux/cmd-new-session.c24
-rw-r--r--usr.bin/tmux/cmd-new-window.c4
-rw-r--r--usr.bin/tmux/cmd-queue.c26
-rw-r--r--usr.bin/tmux/cmd-split-window.c4
-rw-r--r--usr.bin/tmux/cmd.c61
-rw-r--r--usr.bin/tmux/tmux.13
-rw-r--r--usr.bin/tmux/tmux.h5
7 files changed, 73 insertions, 54 deletions
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c
index 869b7fbb7b0..0576806e203 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.51 2013/10/10 12:00:21 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.52 2013/10/10 12:07:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,9 +34,10 @@ enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_new_session_entry = {
"new-session", "new",
- "AdDF:n:Ps:t:x:y:", 0, 1,
- "[-AdDP] [-F format] [-n window-name] [-s session-name] "
- CMD_TARGET_SESSION_USAGE " [-x width] [-y height] [command]",
+ "Ac:dDF:n:Ps:t:x:y:", 0, 1,
+ "[-AdDP] [-c start-directory] [-F format] [-n window-name] "
+ "[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] [-y height] "
+ "[command]",
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON,
NULL,
cmd_new_session_exec
@@ -52,8 +53,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
struct environ env;
struct termios tio, *tiop;
struct passwd *pw;
- const char *newname, *target, *update, *cwd, *errstr;
- const char *template;
+ const char *newname, *target, *update, *base, *cwd;
+ const char *errstr, *template;
char *cmd, *cause, *cp;
int detached, idx;
u_int sx, sy;
@@ -126,14 +127,19 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
/* Get the new session working directory. */
if (c != NULL && c->cwd != NULL)
- cwd = c->cwd;
+ base = c->cwd;
else {
pw = getpwuid(getuid());
if (pw->pw_dir != NULL && *pw->pw_dir != '\0')
- cwd = pw->pw_dir;
+ base = pw->pw_dir;
else
- cwd = "/";
+ base = "/";
}
+ if (args_has(args, 'c'))
+ cwd = args_get(args, 'c');
+ else
+ cwd = options_get_string(&global_s_options, "default-path");
+ cwd = cmd_default_path(base, base, cwd);
/* Find new session size. */
if (c != NULL) {
diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c
index 305a7102d01..e04cd9fdda7 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.33 2013/10/10 12:00:21 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.34 2013/10/10 12:07:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -102,7 +102,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
cmd = options_get_string(&s->options, "default-command");
else
cmd = args->argv[0];
- cwd = cmd_get_default_path(cmdq, args_get(args, 'c'));
+ cwd = cmdq_default_path(cmdq, args_get(args, 'c'));
if (idx == -1)
idx = -1 - options_get_number(&s->options, "base-index");
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index c1b38a03556..0e3a8c2fb6d 100644
--- a/usr.bin/tmux/cmd-queue.c
+++ b/usr.bin/tmux/cmd-queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-queue.c,v 1.11 2013/10/10 12:04:38 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.12 2013/10/10 12:07:36 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -283,3 +283,27 @@ cmdq_flush(struct cmd_q *cmdq)
}
cmdq->item = NULL;
}
+
+/* Get default path using command queue. */
+const char *
+cmdq_default_path(struct cmd_q *cmdq, const char *cwd)
+{
+ struct client *c = cmdq->client;
+ struct session *s;
+ const char *current;
+
+ if ((s = cmd_current_session(cmdq, 0)) == NULL)
+ return (NULL);
+
+ if (cwd == NULL)
+ cwd = options_get_string(&s->options, "default-path");
+
+ if (c != NULL && c->session == NULL && c->cwd != NULL)
+ current = c->cwd;
+ else if (s->curw != NULL)
+ current = get_proc_cwd(s->curw->window->active->fd);
+ else
+ current = NULL;
+
+ return (cmd_default_path(s->cwd, current, cwd));
+}
diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c
index f6bea1c0c44..67ff0e7d145 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.44 2013/10/10 12:04:13 nicm Exp $ */
+/* $OpenBSD: cmd-split-window.c,v 1.45 2013/10/10 12:07:36 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -83,7 +83,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
cmd = options_get_string(&s->options, "default-command");
else
cmd = args->argv[0];
- cwd = cmd_get_default_path(cmdq, args_get(args, 'c'));
+ cwd = cmdq_default_path(cmdq, args_get(args, 'c'));
type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'h'))
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c
index 1d6783bdc0f..dc866299417 100644
--- a/usr.bin/tmux/cmd.c
+++ b/usr.bin/tmux/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.86 2013/10/10 12:00:24 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.87 2013/10/10 12:07:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1279,68 +1279,55 @@ cmd_template_replace(const char *template, const char *s, int idx)
}
/*
- * Return the default path for a new pane, using the given path or the
- * default-path option if it is NULL. Several special values are accepted: the
- * empty string or relative path for the current pane's working directory, ~
- * for the user's home, - for the session working directory, . for the tmux
- * server's working directory. The default on failure is the session's working
- * directory.
+ * Return the default path for a new pane. Several special values are accepted:
+ * the empty string or relative path for the current working directory,
+ * ~ for the user's home, - for the base working directory, . for the server
+ * working directory.
*/
const char *
-cmd_get_default_path(struct cmd_q *cmdq, const char *cwd)
+cmd_default_path(const char *base, const char *current, const char *in)
{
- struct client *c = cmdq->client;
- struct session *s;
- struct environ_entry *envent;
const char *root;
+ struct environ_entry *envent;
char tmp[MAXPATHLEN];
struct passwd *pw;
int n;
size_t skip;
static char path[MAXPATHLEN];
- if ((s = cmd_current_session(cmdq, 0)) == NULL)
- return (NULL);
-
- if (cwd == NULL)
- cwd = options_get_string(&s->options, "default-path");
-
skip = 1;
- if (strcmp(cwd, "$HOME") == 0 || strncmp(cwd, "$HOME/", 6) == 0) {
+ if (strcmp(in, "$HOME") == 0 || strncmp(in, "$HOME/", 6) == 0) {
/* User's home directory - $HOME. */
skip = 5;
goto find_home;
- } else if (cwd[0] == '~' && (cwd[1] == '\0' || cwd[1] == '/')) {
+ } else if (in[0] == '~' && (in[1] == '\0' || in[1] == '/')) {
/* User's home directory - ~. */
goto find_home;
- } else if (cwd[0] == '-' && (cwd[1] == '\0' || cwd[1] == '/')) {
- /* Session working directory. */
- root = s->cwd;
+ } else if (in[0] == '-' && (in[1] == '\0' || in[1] == '/')) {
+ /* Base working directory. */
+ root = base;
goto complete_path;
- } else if (cwd[0] == '.' && (cwd[1] == '\0' || cwd[1] == '/')) {
+ } else if (in[0] == '.' && (in[1] == '\0' || in[1] == '/')) {
/* Server working directory. */
if (getcwd(tmp, sizeof tmp) != NULL) {
root = tmp;
goto complete_path;
}
- return (s->cwd);
- } else if (*cwd == '/') {
+ return ("/");
+ } else if (*in == '/') {
/* Absolute path. */
- return (cwd);
+ return (in);
} else {
/* Empty or relative path. */
- if (c != NULL && c->session == NULL && c->cwd != NULL)
- root = c->cwd;
- else if (s->curw != NULL)
- root = get_proc_cwd(s->curw->window->active->fd);
+ if (current != NULL)
+ root = current;
else
- return (s->cwd);
+ return (base);
skip = 0;
- if (root != NULL)
- goto complete_path;
+ goto complete_path;
}
- return (s->cwd);
+ return (base);
find_home:
envent = environ_find(&global_environ, "HOME");
@@ -1349,15 +1336,15 @@ find_home:
else if ((pw = getpwuid(getuid())) != NULL)
root = pw->pw_dir;
else
- return (s->cwd);
+ return (base);
complete_path:
if (root[skip] == '\0') {
strlcpy(path, root, sizeof path);
return (path);
}
- n = snprintf(path, sizeof path, "%s/%s", root, cwd + skip);
+ n = snprintf(path, sizeof path, "%s/%s", root, in + skip);
if (n > 0 && (size_t)n < sizeof path)
return (path);
- return (s->cwd);
+ return (base);
}
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index bdf31549b13..2a77eacc138 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.370 2013/10/10 12:02:55 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.371 2013/10/10 12:07:37 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -672,6 +672,7 @@ Lock all clients attached to
.Ar target-session .
.It Xo Ic new-session
.Op Fl AdDP
+.Op Fl c Ar start-directory
.Op Fl F Ar format
.Op Fl n Ar window-name
.Op Fl s Ar session-name
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index b2413d1cc91..5f1f2a61c00 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.420 2013/10/10 12:02:24 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.421 2013/10/10 12:07:37 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1770,7 +1770,7 @@ int cmd_find_index(struct cmd_q *, const char *,
struct winlink *cmd_find_pane(struct cmd_q *, const char *, struct session **,
struct window_pane **);
char *cmd_template_replace(const char *, const char *, int);
-const char *cmd_get_default_path(struct cmd_q *, const char *);
+const char *cmd_default_path(const char *, const char *, const char *);
extern const struct cmd_entry *cmd_table[];
extern const struct cmd_entry cmd_attach_session_entry;
extern const struct cmd_entry cmd_bind_key_entry;
@@ -1879,6 +1879,7 @@ void cmdq_run(struct cmd_q *, struct cmd_list *);
void cmdq_append(struct cmd_q *, struct cmd_list *);
int cmdq_continue(struct cmd_q *);
void cmdq_flush(struct cmd_q *);
+const char *cmdq_default_path(struct cmd_q *, const char *);
/* cmd-string.c */
int cmd_string_parse(const char *, struct cmd_list **, const char *,