mirror of
https://github.com/tmux/tmux.git
synced 2025-01-05 23:38:48 +00: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
c71844de63
commit
14fad6a5cc
@ -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);
|
||||
}
|
||||
|
24
tmux.1
24
tmux.1
@ -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
|
||||
@ -1568,7 +1583,7 @@ Rename the current window, or the window at
|
||||
if specified, to
|
||||
.Ar new-name .
|
||||
.It Xo Ic resize-pane
|
||||
.Op Fl DLRU
|
||||
.Op Fl DLRUZ
|
||||
.Op Fl t Ar target-pane
|
||||
.Op Fl x Ar width
|
||||
.Op Fl y Ar height
|
||||
@ -1592,6 +1607,11 @@ or
|
||||
The
|
||||
.Ar adjustment
|
||||
is given in lines or cells (the default is 1).
|
||||
.Pp
|
||||
With
|
||||
.Fl Z ,
|
||||
the active pane is toggled between occupying the whole of the window and its
|
||||
normal position in the layout.
|
||||
.It Xo Ic respawn-pane
|
||||
.Op Fl k
|
||||
.Op Fl t Ar target-pane
|
||||
|
12
tmux.h
12
tmux.h
@ -929,7 +929,9 @@ struct window_pane {
|
||||
u_int id;
|
||||
|
||||
struct window *window;
|
||||
|
||||
struct layout_cell *layout_cell;
|
||||
struct layout_cell *saved_layout_cell;
|
||||
|
||||
u_int sx;
|
||||
u_int sy;
|
||||
@ -994,6 +996,7 @@ struct window {
|
||||
|
||||
int lastlayout;
|
||||
struct layout_cell *layout_root;
|
||||
struct layout_cell *saved_layout_root;
|
||||
|
||||
u_int sx;
|
||||
u_int sy;
|
||||
@ -1003,6 +1006,7 @@ struct window {
|
||||
#define WINDOW_ACTIVITY 0x2
|
||||
#define WINDOW_REDRAW 0x4
|
||||
#define WINDOW_SILENCE 0x8
|
||||
#define WINDOW_ZOOMED 0x10
|
||||
|
||||
struct options options;
|
||||
|
||||
@ -1836,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 *);
|
||||
@ -1929,6 +1936,7 @@ void server_push_stdout(struct client *);
|
||||
void server_push_stderr(struct client *);
|
||||
int server_set_stdin_callback(struct client *, void (*)(struct client *,
|
||||
int, void *), void *, char **);
|
||||
void server_unzoom_window(struct window *);
|
||||
|
||||
/* status.c */
|
||||
int status_out_cmp(struct status_out *, struct status_out *);
|
||||
@ -2132,6 +2140,8 @@ struct window_pane *window_find_string(struct window *, const char *);
|
||||
void window_set_active_pane(struct window *, struct window_pane *);
|
||||
struct window_pane *window_add_pane(struct window *, u_int);
|
||||
void window_resize(struct window *, u_int, u_int);
|
||||
int window_zoom(struct window_pane *);
|
||||
int window_unzoom(struct window *);
|
||||
void window_remove_pane(struct window *, struct window_pane *);
|
||||
struct window_pane *window_pane_at_index(struct window *, u_int);
|
||||
struct window_pane *window_pane_next_by_number(struct window *,
|
||||
@ -2188,7 +2198,7 @@ void layout_fix_panes(struct window *, u_int, u_int);
|
||||
u_int layout_resize_check(struct layout_cell *, enum layout_type);
|
||||
void layout_resize_adjust(
|
||||
struct layout_cell *, enum layout_type, int);
|
||||
void layout_init(struct window *);
|
||||
void layout_init(struct window *, struct window_pane *);
|
||||
void layout_free(struct window *);
|
||||
void layout_resize(struct window *, u_int, u_int);
|
||||
void layout_resize_pane(struct window_pane *, enum layout_type,
|
||||
|
Loading…
Reference in New Issue
Block a user