Allow choose commands to be used outside tmux, so long as at least one

client is attached.
This commit is contained in:
Nicholas Marriott
2013-03-21 16:09:59 +00:00
parent 8903c1f167
commit 180faf73af
8 changed files with 181 additions and 258 deletions

View File

@ -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);
}