summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-choose-buffer.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2012-06-25 14:27:25 +0000
committernicm <nicm@openbsd.org>2012-06-25 14:27:25 +0000
commitac50be73bbb50bd2c5ecef79dd9e073752a8bc1e (patch)
tree8ef5cb249f5ab74ef931a3d68740be98a8c76976 /usr.bin/tmux/cmd-choose-buffer.c
parentClean up and simplify the choose mode code, from Thomas Adam. (diff)
downloadwireguard-openbsd-ac50be73bbb50bd2c5ecef79dd9e073752a8bc1e.tar.xz
wireguard-openbsd-ac50be73bbb50bd2c5ecef79dd9e073752a8bc1e.zip
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-buffer.c')
-rw-r--r--usr.bin/tmux/cmd-choose-buffer.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/usr.bin/tmux/cmd-choose-buffer.c b/usr.bin/tmux/cmd-choose-buffer.c
index 056c7138d0c..a41247fb0d2 100644
--- a/usr.bin/tmux/cmd-choose-buffer.c
+++ b/usr.bin/tmux/cmd-choose-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-choose-buffer.c,v 1.6 2012/06/25 14:08:55 nicm Exp $ */
+/* $OpenBSD: cmd-choose-buffer.c,v 1.7 2012/06/25 14:27:25 nicm Exp $ */
/*
* Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -48,8 +48,9 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
struct window_choose_data *cdata;
struct winlink *wl;
struct paste_buffer *pb;
- u_int idx;
+ char *action, *action_data;
const char *template;
+ u_int idx;
if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively");
@@ -68,14 +69,14 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
return (0);
+ if (args->argc != 0)
+ action = xstrdup(args->argv[0]);
+ else
+ action = xstrdup("paste-buffer -b '%%'");
+
idx = 0;
while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
cdata = window_choose_data_create(ctx);
- if (args->argc != 0)
- cdata->action = xstrdup(args->argv[0]);
- else
- cdata->action = xstrdup("paste-buffer -b '%%'");
-
cdata->idx = idx - 1;
cdata->client->references++;
@@ -83,8 +84,13 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
format_add(cdata->ft, "line", "%u", idx - 1);
format_paste_buffer(cdata->ft, pb);
+ xasprintf(&action_data, "%u", idx - 1);
+ cdata->command = cmd_template_replace(action, action_data, 1);
+ xfree(action_data);
+
window_choose_add(wl->window->active, cdata);
}
+ xfree(action);
window_choose_ready(wl->window->active,
0, cmd_choose_buffer_callback, cmd_choose_buffer_free);
@@ -100,7 +106,6 @@ cmd_choose_buffer_callback(struct window_choose_data *cdata)
if (cdata->client->flags & CLIENT_DEAD)
return;
- xasprintf(&cdata->raw_format, "%u", cdata->idx);
window_choose_ctx(cdata);
}
@@ -114,8 +119,7 @@ cmd_choose_buffer_free(struct window_choose_data *data)
cdata->client->references--;
+ xfree(cdata->command);
xfree(cdata->ft_template);
- xfree(cdata->action);
- xfree(cdata->raw_format);
xfree(cdata);
}