Hello, I realized I wasn't destroying the groups correctly (just deleting the sessions). I've updated the patch to reflect that change and attached it here. Unless there's anything you see when you look at the diff, I'm happy with it.
-- You received this message because you are subscribed to the Google Groups "tmux-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/959d4658-4964-404d-9124-1d8c3abc7f5cn%40googlegroups.com.
>From d59bac199a15e2b337f61fc58a6dc3130dc23a8e Mon Sep 17 00:00:00 2001 From: jakergrossman <[email protected]> Date: Sat, 4 Sep 2021 12:45:18 -0500 Subject: [PATCH] Add targeting groups with kill-session --- cmd-kill-session.c | 27 +++++++++++++++++++++++++-- session.c | 3 +-- tmux.h | 1 + 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/cmd-kill-session.c b/cmd-kill-session.c index 19a8d495..708f16af 100644 --- a/cmd-kill-session.c +++ b/cmd-kill-session.c @@ -33,8 +33,8 @@ const struct cmd_entry cmd_kill_session_entry = { .name = "kill-session", .alias = NULL, - .args = { "aCt:", 0, 0, NULL }, - .usage = "[-aC] " CMD_TARGET_SESSION_USAGE, + .args = { "aCg:t:", 0, 0, NULL }, + .usage = "[-aC]" CMD_TARGET_SESSION_USAGE " [-g group-name]", .target = { 't', CMD_FIND_SESSION, 0 }, @@ -48,8 +48,15 @@ cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item) struct args *args = cmd_get_args(self); struct cmd_find_state *target = cmdq_get_target(item); struct session *s = target->s, *sloop, *stmp; + struct session_group *sg; + const char *group; struct winlink *wl; + if (args_has(args, 'g') && args_has(args, 't')) { + cmdq_error(item, "can't target session and group (-t/-g)"); + return (CMD_RETURN_ERROR); + } + if (args_has(args, 'C')) { RB_FOREACH(wl, winlinks, &s->windows) { wl->window->flags &= ~WINDOW_ALERTFLAGS; @@ -63,6 +70,22 @@ cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item) session_destroy(sloop, 1, __func__); } } + } else if (args_has(args, 'g')) { + group = args_get(args, 'g'); + + if ((sg = session_group_find(group)) == NULL) + { + cmdq_error(item, "can't find group: %s", group); + return (CMD_RETURN_ERROR); + } + + TAILQ_FOREACH_SAFE(sloop, &sg->sessions, gentry, stmp) { + session_group_remove(sloop); + server_destroy_session(sloop); + session_destroy(sloop, 1, __func__); + } + + } else { server_destroy_session(s); session_destroy(s, 1, __func__); diff --git a/session.c b/session.c index 8665cccc..83f502d0 100644 --- a/session.c +++ b/session.c @@ -37,7 +37,6 @@ static void session_lock_timer(int, short, void *); static struct winlink *session_next_alert(struct winlink *); static struct winlink *session_previous_alert(struct winlink *); -static void session_group_remove(struct session *); static void session_group_synchronize1(struct session *, struct session *); int @@ -560,7 +559,7 @@ session_group_add(struct session_group *sg, struct session *s) } /* Remove a session from its group and destroy the group if empty. */ -static void +void session_group_remove(struct session *s) { struct session_group *sg; diff --git a/tmux.h b/tmux.h index c95daa46..a80484f6 100644 --- a/tmux.h +++ b/tmux.h @@ -3029,6 +3029,7 @@ struct session_group *session_group_contains(struct session *); struct session_group *session_group_find(const char *); struct session_group *session_group_new(const char *); void session_group_add(struct session_group *, struct session *); +void session_group_remove(struct session *s); void session_group_synchronize_to(struct session *); void session_group_synchronize_from(struct session *); u_int session_group_count(struct session_group *); -- 2.33.0
