summaryrefslogtreecommitdiffstats
path: root/cmd-choose-tree.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2013-03-21 16:09:59 +0000
committerNicholas Marriott <nicm@openbsd.org>2013-03-21 16:09:59 +0000
commit180faf73afe07d35e6002993a70d5fe63549ffce (patch)
treee1a06d7b7042fd2afeb84507c8795a6a5d53cd3e /cmd-choose-tree.c
parent8903c1f167839569b7514508b38988aa6486575c (diff)
Allow choose commands to be used outside tmux, so long as at least one
client is attached.
Diffstat (limited to 'cmd-choose-tree.c')
-rw-r--r--cmd-choose-tree.c42
1 files changed, 8 insertions, 34 deletions
diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c
index b274d561..a111bc07 100644
--- a/cmd-choose-tree.c
+++ b/cmd-choose-tree.c
@@ -34,9 +34,6 @@
enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_ctx *);
-void cmd_choose_tree_callback(struct window_choose_data *);
-void cmd_choose_tree_free(struct window_choose_data *);
-
const struct cmd_entry cmd_choose_tree_entry = {
"choose-tree", NULL,
"S:W:swub:c:t:", 0, 1,
@@ -74,6 +71,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
struct args *args = self->args;
struct winlink *wl, *wm;
struct session *s, *s2;
+ struct client *c;
struct window_choose_data *wcd = NULL;
const char *ses_template, *win_template;
char *final_win_action, *cur_win_template;
@@ -86,12 +84,13 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
ses_template = win_template = NULL;
ses_action = win_action = NULL;
- if (ctx->curclient == NULL) {
- ctx->error(ctx, "must be run interactively");
+ if ((c = cmd_current_client(ctx)) == NULL) {
+ ctx->error(ctx, "no client available");
return (CMD_RETURN_ERROR);
}
- s = ctx->curclient->session;
+ if ((s = c->session) == NULL)
+ return (CMD_RETURN_ERROR);
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
@@ -175,7 +174,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
}
wcd = window_choose_add_session(wl->window->active,
- ctx, s2, ses_template, (char *)ses_action, idx_ses);
+ c, s2, ses_template, (char *)ses_action, idx_ses);
/* If we're just choosing sessions, skip choosing windows. */
if (sflag && !wflag) {
@@ -213,7 +212,7 @@ windows_only:
cur_win_template = final_win_template_last;
window_choose_add_window(wl->window->active,
- ctx, s2, wm, cur_win_template,
+ c, s2, wm, cur_win_template,
final_win_action,
(wflag && !sflag) ? win_ses : idx_ses);
@@ -230,35 +229,10 @@ windows_only:
free(final_win_template_middle);
free(final_win_template_last);
- window_choose_ready(wl->window->active, cur_win,
- cmd_choose_tree_callback, cmd_choose_tree_free);
+ window_choose_ready(wl->window->active, cur_win, NULL);
if (args_has(args, 'u'))
window_choose_expand_all(wl->window->active);
return (CMD_RETURN_NORMAL);
}
-
-void
-cmd_choose_tree_callback(struct window_choose_data *cdata)
-{
- if (cdata == NULL)
- return;
-
- if (cdata->client->flags & CLIENT_DEAD)
- return;
-
- window_choose_ctx(cdata);
-}
-
-void
-cmd_choose_tree_free(struct window_choose_data *cdata)
-{
- cdata->session->references--;
- cdata->client->references--;
-
- free(cdata->ft_template);
- free(cdata->command);
- format_free(cdata->ft);
- free(cdata);
-}