mirror of
https://github.com/tmate-io/tmate.git
synced 2024-12-24 15:48:58 +01:00
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.
This commit is contained in:
parent
c5239c5984
commit
f339cfd315
@ -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')));
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
17
tmux.1
17
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
|
||||
|
3
tmux.h
3
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 *);
|
||||
|
Loading…
Reference in New Issue
Block a user