diff options
author | Tiago Cunha <tcunha@gmx.com> | 2012-07-04 11:03:20 +0000 |
---|---|---|
committer | Tiago Cunha <tcunha@gmx.com> | 2012-07-04 11:03:20 +0000 |
commit | 7e02d2f459531107770e925bebf1fbc548719de0 (patch) | |
tree | bbad76367cef32639ece94dad81b70167140657a /cmd-choose-client.c | |
parent | 5761712799beb830ba18e27b3300aaa248ff83d4 (diff) | |
download | rtmux-7e02d2f459531107770e925bebf1fbc548719de0.tar.gz rtmux-7e02d2f459531107770e925bebf1fbc548719de0.tar.bz2 rtmux-7e02d2f459531107770e925bebf1fbc548719de0.zip |
Sync OpenBSD patchset 1143:
Provide common helper function for adding windows and sessions to choose
lists and expand %% in command before using it rather than at callback
time. From Thomas Adam.
Diffstat (limited to 'cmd-choose-client.c')
-rw-r--r-- | cmd-choose-client.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/cmd-choose-client.c b/cmd-choose-client.c index 230ff4a8..5b3e6bf4 100644 --- a/cmd-choose-client.c +++ b/cmd-choose-client.c @@ -54,6 +54,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx) struct winlink *wl; struct client *c; const char *template; + char *action; u_int i, idx, cur; if (ctx->curclient == NULL) { @@ -70,6 +71,11 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx) if ((template = args_get(args, 'F')) == NULL) template = DEFAULT_CLIENT_TEMPLATE; + if (args->argc != 0) + action = xstrdup(args->argv[0]); + else + action = xstrdup("detach-client -t '%%'"); + cur = idx = 0; for (i = 0; i < ARRAY_LENGTH(&clients); i++) { c = ARRAY_ITEM(&clients, i); @@ -80,11 +86,6 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx) idx++; cdata = window_choose_data_create(ctx); - if (args->argc != 0) - cdata->action = xstrdup(args->argv[0]); - else - cdata->action = xstrdup("detach-client -t '%%'"); - cdata->idx = i; cdata->client->references++; @@ -93,8 +94,11 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx) format_session(cdata->ft, c->session); format_client(cdata->ft, c); + cdata->command = cmd_template_replace(action, c->tty.path, 1); + window_choose_add(wl->window->active, cdata); } + xfree(action); window_choose_ready(wl->window->active, cur, cmd_choose_client_callback, cmd_choose_client_free); @@ -118,7 +122,6 @@ cmd_choose_client_callback(struct window_choose_data *cdata) if (c == NULL || c->session == NULL) return; - xasprintf(&cdata->raw_format, "%s", c->tty.path); window_choose_ctx(cdata); } @@ -131,7 +134,7 @@ cmd_choose_client_free(struct window_choose_data *cdata) cdata->client->references--; xfree(cdata->ft_template); - xfree(cdata->action); + xfree(cdata->command); format_free(cdata->ft); xfree(cdata); } |