diff --git a/cmd-attach-session.c b/cmd-attach-session.c index 5c8f76ed..07185737 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -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/cmd-new-session.c b/cmd-new-session.c index 323bc16a..3b1e917f 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -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/tmux.1 b/tmux.1 index 0f385feb..8e536b67 100644 --- a/tmux.1 +++ b/tmux.1 @@ -670,7 +670,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 @@ -701,6 +701,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/tmux.h b/tmux.h index c29e1240..0df1f4d8 100644 --- a/tmux.h +++ b/tmux.h @@ -1836,6 +1836,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 *);