summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2013-03-24 09:58:40 +0000
committernicm <nicm@openbsd.org>2013-03-24 09:58:40 +0000
commiteb088ac5775e56b5f2e77bfa03a7d40a925978fa (patch)
tree9e3e467efdb5dbf05ad4cf1fbd50d3b6b76897ab
parentAdd resize-pane -Z to temporary zoom the active pane to occupy the full (diff)
downloadwireguard-openbsd-eb088ac5775e56b5f2e77bfa03a7d40a925978fa.tar.xz
wireguard-openbsd-eb088ac5775e56b5f2e77bfa03a7d40a925978fa.zip
Add -A flag to new-session to make it behave like attach-session if the
session exists. If -A is used, -D behaves like -d to attach-session.
-rw-r--r--usr.bin/tmux/cmd-attach-session.c22
-rw-r--r--usr.bin/tmux/cmd-new-session.c10
-rw-r--r--usr.bin/tmux/tmux.119
-rw-r--r--usr.bin/tmux/tmux.h5
4 files changed, 43 insertions, 13 deletions
diff --git a/usr.bin/tmux/cmd-attach-session.c b/usr.bin/tmux/cmd-attach-session.c
index c5aee1ecd9f..412bd883196 100644
--- a/usr.bin/tmux/cmd-attach-session.c
+++ b/usr.bin/tmux/cmd-attach-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-attach-session.c,v 1.23 2013/03/24 09:54:10 nicm Exp $ */
+/* $OpenBSD: cmd-attach-session.c,v 1.24 2013/03/24 09:58:40 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -39,9 +39,8 @@ const struct cmd_entry cmd_attach_session_entry = {
};
enum cmd_retval
-cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
+cmd_attach_session(struct cmd_q *cmdq, const char* tflag, int dflag, int rflag)
{
- struct args *args = self->args;
struct session *s;
struct client *c;
const char *update;
@@ -53,14 +52,14 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
- if ((s = cmd_find_session(cmdq, args_get(args, 't'), 1)) == NULL)
+ if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
return (CMD_RETURN_ERROR);
if (cmdq->client == NULL)
return (CMD_RETURN_NORMAL);
if (cmdq->client->session != NULL) {
- if (args_has(self->args, 'd')) {
+ if (dflag) {
/*
* Can't use server_write_session in case attaching to
* the same session as currently attached to.
@@ -87,10 +86,10 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
- if (args_has(self->args, 'r'))
+ if (rflag)
cmdq->client->flags |= CLIENT_READONLY;
- if (args_has(self->args, 'd'))
+ if (dflag)
server_write_session(s, MSG_DETACH, NULL, 0);
update = options_get_string(&s->options, "update-environment");
@@ -110,3 +109,12 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL);
}
+
+enum cmd_retval
+cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
+{
+ struct args *args = self->args;
+
+ return (cmd_attach_session(cmdq, args_get(args, 't'),
+ args_has(args, 'd'), args_has(args, 'r')));
+}
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c
index 18fe6b3434c..f62a74417a1 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.48 2013/03/24 09:54:10 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.49 2013/03/24 09:58:40 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -35,8 +35,8 @@ enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_new_session_entry = {
"new-session", "new",
- "dn:s:t:x:y:", 0, 1,
- "[-d] [-n window-name] [-s session-name] " CMD_TARGET_SESSION_USAGE
+ "AdDn:s:t:x:y:", 0, 1,
+ "[-AdD] [-n window-name] [-s session-name] " CMD_TARGET_SESSION_USAGE
" [-x width] [-y height] [command]",
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON,
NULL,
@@ -76,6 +76,10 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
if (session_find(newname) != NULL) {
+ if (args_has(args, 'A')) {
+ return (cmd_attach_session(cmdq, newname,
+ args_has(args, 'D'), 0));
+ }
cmdq_error(cmdq, "duplicate session: %s", newname);
return (CMD_RETURN_ERROR);
}
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 43b5ff6b34e..114b03e5557 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.337 2013/03/24 09:57:59 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.338 2013/03/24 09:58:40 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -666,7 +666,7 @@ command.
Lock all clients attached to
.Ar target-session .
.It Xo Ic new-session
-.Op Fl d
+.Op Fl AdD
.Op Fl n Ar window-name
.Op Fl s Ar session-name
.Op Fl t Ar target-session
@@ -697,6 +697,21 @@ If run from a terminal, any
.Xr termios 4
special characters are saved and used for new windows in the new session.
.Pp
+The
+.Fl A
+flag makes
+.Ic new-session
+behave like
+.Ic attach-session
+if
+.Ar session-name
+already exists; in the case,
+.Fl D
+behaves like
+.Fl d
+to
+.Ic attach-session .
+.Pp
If
.Fl t
is given, the new session is
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 194ca9d1804..652c6b9f6d0 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.398 2013/03/24 09:57:59 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.399 2013/03/24 09:58:40 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1840,6 +1840,9 @@ extern const struct cmd_entry cmd_unbind_key_entry;
extern const struct cmd_entry cmd_unlink_window_entry;
extern const struct cmd_entry cmd_up_pane_entry;
+/* cmd-attach-session.c */
+enum cmd_retval cmd_attach_session(struct cmd_q *, const char*, int, int);
+
/* cmd-list.c */
struct cmd_list *cmd_list_parse(int, char **, const char *, u_int, char **);
void cmd_list_free(struct cmd_list *);