Hi,

I've gotten -g working for kill-session, but there are more kinks with 
adding -g to rename-session (it works, but I'm not happy with it. I feel 
there is more to do before it is ready for feedback). I've attached a patch 
for cmd-kill-session.c below.

I'm not super stoked about the updated usage or the error message for 
kill-session. I decided to implement it so -g with -t is an error, but I'm 
not sure how to indicate "either or" in the usage, or how to to tell the 
user they cannot use both. I'd love opinions on that, as well as anything 
else!

On Friday, September 3, 2021 at 1:17:18 PM UTC-5 [email protected] 
wrote:

> Hi
>
> I'd probably go for -g with a group name. If -t is there as well you can 
> either make it an error or only kill the group if the given session is in 
> it.
>
>
> On Fri, 3 Sep 2021, 19:00 Jake Grossman, <[email protected]> wrote:
>
>> I was tinkering trying to implement one of the suggested features from 
>> https://github.com/tmux/tmux/issues/2346. First off, is anyone already 
>> doing this? Don't want to duplicate work!
>>
>> Should it be a flag for the target, or it's own target (i.e. kill-session 
>> -g -t foo vs kill-session -g foo)? Which would be preferable?
>>
>> Thanks,
>> Jake
>>
>> -- 
>> 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/CAMaYsBciVDpy85NCByzeejrHvJ0gAjLPp%2BMoOWfTv8WvaXa7tQ%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/tmux-users/CAMaYsBciVDpy85NCByzeejrHvJ0gAjLPp%2BMoOWfTv8WvaXa7tQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/bd997a80-ecb1-4f40-8515-0d3974f0625en%40googlegroups.com.
>From 9fc48e12d34fd28640a5c24f28d8df53147a663e 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 | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/cmd-kill-session.c b/cmd-kill-session.c
index 19a8d495..a959c6b1 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		*groupname;
 	struct winlink		*wl;
 
+	if (args_has(args, 'g') && args_has(args, 't')) {
+		cmdq_error(item, "can't use -g/-t twice");
+		return (CMD_RETURN_ERROR);
+	}
+
 	if (args_has(args, 'C')) {
 		RB_FOREACH(wl, winlinks, &s->windows) {
 			wl->window->flags &= ~WINDOW_ALERTFLAGS;
@@ -63,6 +70,19 @@ cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
 				session_destroy(sloop, 1, __func__);
 			}
 		}
+	} else if (args_has(args, 'g')) {
+		groupname = args_get(args, 'g');
+
+		if ((sg = session_group_find(groupname)) == NULL)
+		{
+			cmdq_error(item, "can't find group: %s", groupname);
+			return (CMD_RETURN_ERROR);
+		}
+
+		TAILQ_FOREACH_SAFE(sloop, &sg->sessions, gentry, stmp) {
+			server_destroy_session(sloop);
+			session_destroy(sloop, 1, __func__);
+		}
 	} else {
 		server_destroy_session(s);
 		session_destroy(s, 1, __func__);
-- 
2.33.0

Reply via email to