Add new-session -X and attach-session -x to send SIGHUP to parent when

detaching (like detach-client -P). From Colin Watson in GitHub issue
1773.
pull/1782/head
nicm 2019-06-03 18:28:37 +00:00
parent 900238a306
commit 4ca1de1b8b
4 changed files with 35 additions and 15 deletions

View File

@ -37,8 +37,8 @@ const struct cmd_entry cmd_attach_session_entry = {
.name = "attach-session",
.alias = "attach",
.args = { "c:dErt:", 0, 0 },
.usage = "[-dEr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
.args = { "c:dErt:x", 0, 0 },
.usage = "[-dErx] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
/* -t is special */
@ -48,7 +48,7 @@ const struct cmd_entry cmd_attach_session_entry = {
enum cmd_retval
cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
int rflag, const char *cflag, int Eflag)
int xflag, int rflag, const char *cflag, int Eflag)
{
struct cmd_find_state *current = &item->shared->current;
enum cmd_find_type type;
@ -58,6 +58,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
struct winlink *wl;
struct window_pane *wp;
char *cause;
enum msgtype msgtype;
if (RB_EMPTY(&sessions)) {
cmdq_error(item, "no sessions");
@ -102,11 +103,15 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
c->last_session = c->session;
if (c->session != NULL) {
if (dflag) {
if (dflag || xflag) {
if (xflag)
msgtype = MSG_DETACHKILL;
else
msgtype = MSG_DETACH;
TAILQ_FOREACH(c_loop, &clients, entry) {
if (c_loop->session != s || c == c_loop)
continue;
server_client_detach(c_loop, MSG_DETACH);
server_client_detach(c_loop, msgtype);
}
}
if (!Eflag)
@ -131,11 +136,15 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
if (rflag)
c->flags |= CLIENT_READONLY;
if (dflag) {
if (dflag || xflag) {
if (xflag)
msgtype = MSG_DETACHKILL;
else
msgtype = MSG_DETACH;
TAILQ_FOREACH(c_loop, &clients, entry) {
if (c_loop->session != s || c == c_loop)
continue;
server_client_detach(c_loop, MSG_DETACH);
server_client_detach(c_loop, msgtype);
}
}
if (!Eflag)
@ -169,6 +178,6 @@ cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item)
struct args *args = self->args;
return (cmd_attach_session(item, args_get(args, 't'),
args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c'),
args_has(args, 'E')));
args_has(args, 'd'), args_has(args, 'x'), args_has(args, 'r'),
args_get(args, 'c'), args_has(args, 'E')));
}

View File

@ -39,8 +39,8 @@ const struct cmd_entry cmd_new_session_entry = {
.name = "new-session",
.alias = "new",
.args = { "Ac:dDEF:n:Ps:t:x:y:", 0, -1 },
.usage = "[-AdDEP] [-c start-directory] [-F format] [-n window-name] "
.args = { "Ac:dDEF:n:Ps:t:x:Xy:", 0, -1 },
.usage = "[-AdDEPX] [-c start-directory] [-F format] [-n window-name] "
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
"[-y height] [command]",
@ -105,7 +105,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'A')) {
retval = cmd_attach_session(item,
newname, args_has(args, 'D'),
0, NULL, args_has(args, 'E'));
args_has(args, 'X'), 0, NULL,
args_has(args, 'E'));
free(newname);
return (retval);
}

14
tmux.1
View File

@ -918,7 +918,7 @@ section.
The following commands are available to manage clients and sessions:
.Bl -tag -width Ds
.It Xo Ic attach-session
.Op Fl dEr
.Op Fl dErx
.Op Fl c Ar working-directory
.Op Fl t Ar target-session
.Xc
@ -931,6 +931,10 @@ If used from inside, switch the current client.
If
.Fl d
is specified, any other clients attached to the session are detached.
If
.Fl x
is given, send SIGHUP to the parent process of the client as well as
detaching the client, typically causing it to exit.
.Fl r
signifies the client is read-only (only keys bound to the
.Ic detach-client
@ -1048,7 +1052,7 @@ command.
Lock all clients attached to
.Ar target-session .
.It Xo Ic new-session
.Op Fl AdDEP
.Op Fl AdDEPX
.Op Fl c Ar start-directory
.Op Fl F Ar format
.Op Fl n Ar window-name
@ -1105,6 +1109,12 @@ already exists; in this case,
behaves like
.Fl d
to
.Ic attach-session ,
and
.Fl X
behaves like
.Fl x
to
.Ic attach-session .
.Pp
If

2
tmux.h
View File

@ -2009,7 +2009,7 @@ extern const struct cmd_entry *cmd_table[];
/* cmd-attach-session.c */
enum cmd_retval cmd_attach_session(struct cmdq_item *, const char *, int, int,
const char *, int);
int, const char *, int);
/* cmd-parse.c */
void cmd_parse_empty(struct cmd_parse_input *);