summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/cmd-choose-client.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2012-06-25 14:27:26 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2012-06-25 14:27:26 +0000
commit6efa5cbbbaab6a9cd54bfa31c7f89a7954ac755b (patch)
treeb470fd016536be0a8da8f9a800dc79880b0aafde /usr.bin/tmux/cmd-choose-client.c
parentb992c5e6a1cecafa0cd3133b767bd460f50d0057 (diff)
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 'usr.bin/tmux/cmd-choose-client.c')
-rw-r--r--usr.bin/tmux/cmd-choose-client.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/usr.bin/tmux/cmd-choose-client.c b/usr.bin/tmux/cmd-choose-client.c
index 2e0ada2dfb5..27b2d305bc2 100644
--- a/usr.bin/tmux/cmd-choose-client.c
+++ b/usr.bin/tmux/cmd-choose-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-choose-client.c,v 1.8 2012/06/25 14:08:55 nicm Exp $ */
+/* $OpenBSD: cmd-choose-client.c,v 1.9 2012/06/25 14:27:25 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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);
}