summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2011-04-11 06:44:39 +0000
committerNicholas Marriott <nicm@openbsd.org>2011-04-11 06:44:39 +0000
commit735f87bc668f72fa8c62e579fda82cca2a27f48e (patch)
treea11f7dedee4f013dcf577a6c2d11aa2bd5df14bb
parent98d450ac3adddd87b306a9f16d4738523b60a4ab (diff)
Add -s option to detach all clients attached to a session, from Zac
Sprackett.
-rw-r--r--cmd-detach-client.c30
-rw-r--r--tmux.17
2 files changed, 29 insertions, 8 deletions
diff --git a/cmd-detach-client.c b/cmd-detach-client.c
index 12723ac4..b9a2a910 100644
--- a/cmd-detach-client.c
+++ b/cmd-detach-client.c
@@ -28,7 +28,7 @@ int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_detach_client_entry = {
"detach-client", "detach",
- "t:P", 0, 0,
+ "s:t:P", 0, 0,
"[-P] " CMD_TARGET_CLIENT_USAGE,
CMD_READONLY,
NULL,
@@ -41,14 +41,32 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
struct client *c;
-
- if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
- return (-1);
+ struct session *s;
+ enum msgtype msgtype;
+ u_int i;
if (args_has(args, 'P'))
- server_write_client(c, MSG_DETACHKILL, NULL, 0);
+ msgtype = MSG_DETACHKILL;
else
- server_write_client(c, MSG_DETACH, NULL, 0);
+ msgtype = MSG_DETACH;
+
+ if (args_has(args, 's')) {
+ s = cmd_find_session(ctx, args_get(args, 's'), 0);
+ if (s == NULL)
+ return (-1);
+
+ for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
+ c = ARRAY_ITEM(&clients, i);
+ if (c != NULL && c->session == s)
+ server_write_client(c, msgtype, NULL, 0);
+ }
+ } else {
+ c = cmd_find_client(ctx, args_get(args, 't'));
+ if (c == NULL)
+ return (-1);
+
+ server_write_client(c, msgtype, NULL, 0);
+ }
return (0);
}
diff --git a/tmux.1 b/tmux.1
index 7c5ea455..3450418c 100644
--- a/tmux.1
+++ b/tmux.1
@@ -576,10 +576,13 @@ session.
.It Xo Ic detach-client
.Op Fl P
.Op Fl t Ar target-client
+.Op Fl s Ar target-session
.Xc
.D1 (alias: Ic detach )
-Detach the current client if bound to a key, or the specified client with
-.Fl t .
+Detach the current client if bound to a key, the client specified with
+.Fl t ,
+or all clients currently attached to to the session specified by
+.Fl s .
If
.Fl P
is given, send SIGHUP to the parent process of the client, typically causing it