aboutsummaryrefslogtreecommitdiff
path: root/cmd-choose-session.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2009-08-25 13:53:39 +0000
committerTiago Cunha <tcunha@gmx.com>2009-08-25 13:53:39 +0000
commit8fd77cbb5b9e81a14d52f9ddcf765d3ce557ed86 (patch)
treef15f24cd859da56f60f2fcac20b2b3dd565e0ae3 /cmd-choose-session.c
parentc1653ff65452c01f0c2c41dbcb3c6d0eb241348b (diff)
downloadrtmux-8fd77cbb5b9e81a14d52f9ddcf765d3ce557ed86.tar.gz
rtmux-8fd77cbb5b9e81a14d52f9ddcf765d3ce557ed86.tar.bz2
rtmux-8fd77cbb5b9e81a14d52f9ddcf765d3ce557ed86.zip
Sync OpenBSD patchset 294:
Add a choose-client command and extend choose-{session,window} to accept a template. After a choice is made, %% (or %1) in the template is replaced by the name of the session, window or client suitable for -t and the result executed as a command. So, for example, "choose-window "killw -t '%%'"" will kill the selected window. The defaults if no template is given are (as now) select-window for choose-window, switch-client for choose-session, and detach-client for choose-client (now bound to D).
Diffstat (limited to 'cmd-choose-session.c')
-rw-r--r--cmd-choose-session.c72
1 files changed, 59 insertions, 13 deletions
diff --git a/cmd-choose-session.c b/cmd-choose-session.c
index 279b8c04..3d62281f 100644
--- a/cmd-choose-session.c
+++ b/cmd-choose-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-choose-session.c,v 1.10 2009-07-28 22:12:16 tcunha Exp $ */
+/* $Id: cmd-choose-session.c,v 1.11 2009-08-25 13:53:39 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -27,11 +27,12 @@
int cmd_choose_session_exec(struct cmd *, struct cmd_ctx *);
void cmd_choose_session_callback(void *, int);
+void cmd_choose_session_free(void *);
const struct cmd_entry cmd_choose_session_entry = {
"choose-session", NULL,
- CMD_TARGET_WINDOW_USAGE,
- 0, 0,
+ CMD_TARGET_WINDOW_USAGE " [template]",
+ CMD_ARG01, 0,
cmd_target_init,
cmd_target_parse,
cmd_choose_session_exec,
@@ -40,7 +41,8 @@ const struct cmd_entry cmd_choose_session_entry = {
};
struct cmd_choose_session_data {
- u_int client;
+ u_int client;
+ char *template;
};
int
@@ -79,10 +81,14 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
}
cdata = xmalloc(sizeof *cdata);
+ if (data->arg != NULL)
+ cdata->template = xstrdup(data->arg);
+ else
+ cdata->template = xstrdup("switch-client -t '%%'");
cdata->client = server_client_index(ctx->curclient);
- window_choose_ready(
- wl->window->active, cur, cmd_choose_session_callback, xfree, cdata);
+ window_choose_ready(wl->window->active,
+ cur, cmd_choose_session_callback, cmd_choose_session_free, cdata);
return (0);
}
@@ -92,13 +98,53 @@ cmd_choose_session_callback(void *data, int idx)
{
struct cmd_choose_session_data *cdata = data;
struct client *c;
-
- if (idx != -1 && cdata->client <= ARRAY_LENGTH(&clients) - 1) {
- c = ARRAY_ITEM(&clients, cdata->client);
- if (c != NULL && (u_int) idx <= ARRAY_LENGTH(&sessions) - 1) {
- c->session = ARRAY_ITEM(&sessions, idx);
- recalculate_sizes();
- server_redraw_client(c);
+ struct session *s;
+ struct cmd_list *cmdlist;
+ struct cmd_ctx ctx;
+ char *template, *cause;
+
+ if (idx == -1)
+ return;
+ if (cdata->client > ARRAY_LENGTH(&clients) - 1)
+ return;
+ c = ARRAY_ITEM(&clients, cdata->client);
+
+ if ((u_int) idx > ARRAY_LENGTH(&sessions) - 1)
+ return;
+ s = ARRAY_ITEM(&sessions, idx);
+ if (s == NULL)
+ return;
+ template = cmd_template_replace(cdata->template, s->name, 1);
+
+ if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
+ if (cause != NULL) {
+ *cause = toupper((u_char) *cause);
+ status_message_set(c, "%s", cause);
+ xfree(cause);
}
+ xfree(template);
+ return;
}
+ xfree(template);
+
+ ctx.msgdata = NULL;
+ ctx.curclient = c;
+
+ ctx.error = key_bindings_error;
+ ctx.print = key_bindings_print;
+ ctx.info = key_bindings_info;
+
+ ctx.cmdclient = NULL;
+
+ cmd_list_exec(cmdlist, &ctx);
+ cmd_list_free(cmdlist);
+}
+
+void
+cmd_choose_session_free(void *data)
+{
+ struct cmd_choose_session_data *cdata = data;
+
+ xfree(cdata->template);
+ xfree(cdata);
}