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-02-10 17:52:51 +00:00
parent aadc87f5a7
commit f1ce95915c
8 changed files with 30 additions and 40 deletions

View File

@ -51,11 +51,10 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *template; const char *template;
u_int idx; u_int idx;
if (ctx->curclient == NULL) { if ((c = cmd_current_client(ctx)) == NULL) {
ctx->error(ctx, "must be run interactively"); ctx->error(ctx, "no client available");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
c = ctx->curclient;
if ((template = args_get(args, 'F')) == NULL) if ((template = args_get(args, 'F')) == NULL)
template = CHOOSE_BUFFER_TEMPLATE; template = CHOOSE_BUFFER_TEMPLATE;

View File

@ -57,11 +57,10 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
char *action; char *action;
u_int i, idx, cur; u_int i, idx, cur;
if (ctx->curclient == NULL) { if ((c = cmd_current_client(ctx)) == NULL) {
ctx->error(ctx, "must be run interactively"); ctx->error(ctx, "no client available");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
c = ctx->curclient;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);

View File

@ -47,13 +47,14 @@ enum cmd_retval
cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct args *args = self->args; struct args *args = self->args;
struct client *c;
struct winlink *wl; struct winlink *wl;
const char *list1; const char *list1;
char *template, *item, *copy, *list; char *template, *item, *copy, *list;
u_int idx; u_int idx;
if (ctx->curclient == NULL) { if ((c = cmd_current_client(ctx)) == NULL) {
ctx->error(ctx, "must be run interactively"); ctx->error(ctx, "no client available");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@ -77,7 +78,7 @@ cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
if (*item == '\0') /* no empty entries */ if (*item == '\0') /* no empty entries */
continue; continue;
window_choose_add_item(wl->window->active, ctx, wl, item, window_choose_add_item(wl->window->active, c, wl, item,
template, idx); template, idx);
idx++; idx++;
} }

View File

@ -71,6 +71,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
struct args *args = self->args; struct args *args = self->args;
struct winlink *wl, *wm; struct winlink *wl, *wm;
struct session *s, *s2; struct session *s, *s2;
struct client *c;
struct window_choose_data *wcd = NULL; struct window_choose_data *wcd = NULL;
const char *ses_template, *win_template; const char *ses_template, *win_template;
char *final_win_action, *cur_win_template; char *final_win_action, *cur_win_template;
@ -83,12 +84,13 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
ses_template = win_template = NULL; ses_template = win_template = NULL;
ses_action = win_action = NULL; ses_action = win_action = NULL;
if (ctx->curclient == NULL) { if ((c = cmd_current_client(ctx)) == NULL) {
ctx->error(ctx, "must be run interactively"); ctx->error(ctx, "no client available");
return (CMD_RETURN_ERROR); 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) if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
@ -172,7 +174,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
} }
wcd = window_choose_add_session(wl->window->active, 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 we're just choosing sessions, skip choosing windows. */
if (sflag && !wflag) { if (sflag && !wflag) {
@ -210,7 +212,7 @@ windows_only:
cur_win_template = final_win_template_last; cur_win_template = final_win_template_last;
window_choose_add_window(wl->window->active, window_choose_add_window(wl->window->active,
ctx, s2, wm, cur_win_template, c, s2, wm, cur_win_template,
final_win_action, final_win_action,
(wflag && !sflag) ? win_ses : idx_ses); (wflag && !sflag) ? win_ses : idx_ses);

View File

@ -139,11 +139,10 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *template; const char *template;
u_int i, match_flags; u_int i, match_flags;
if (ctx->curclient == NULL) { if ((c = cmd_current_client(ctx)) == NULL) {
ctx->error(ctx, "must be run interactively"); ctx->error(ctx, "no client available");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
c = ctx->curclient;
s = c->session; s = c->session;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)

21
tmux.1
View File

@ -1078,8 +1078,7 @@ For the meaning of the
flag, see the flag, see the
.Sx FORMATS .Sx FORMATS
section. section.
This command works only from inside This command works only if at least one client is attached.
.Nm .
.It Xo .It Xo
.Ic choose-list .Ic choose-list
.Op Fl l Ar items .Op Fl l Ar items
@ -1105,8 +1104,7 @@ also accepts format specifiers.
For the meaning of this see the For the meaning of this see the
.Sx FORMATS .Sx FORMATS
section. section.
This command works only from inside This command works only if at least one client is attached.
.Nm .
.It Xo .It Xo
.Ic choose-session .Ic choose-session
.Op Fl F Ar format .Op Fl F Ar format
@ -1128,8 +1126,7 @@ For the meaning of the
flag, see the flag, see the
.Sx FORMATS .Sx FORMATS
section. section.
This command works only from inside This command works only if at least one client is attached.
.Nm .
.It Xo .It Xo
.Ic choose-tree .Ic choose-tree
.Op Fl s .Op Fl s
@ -1193,8 +1190,7 @@ and
options, see the options, see the
.Sx FORMATS .Sx FORMATS
section. section.
This command only works from inside This command works only if at least one client is attached.
.Nm .
.It Xo .It Xo
.Ic choose-window .Ic choose-window
.Op Fl F Ar format .Op Fl F Ar format
@ -1216,8 +1212,7 @@ For the meaning of the
flag, see the flag, see the
.Sx FORMATS .Sx FORMATS
section. section.
This command works only from inside This command works only if at least one client is attached.
.Nm .
.It Ic display-panes Op Fl t Ar target-client .It Ic display-panes Op Fl t Ar target-client
.D1 (alias: Ic displayp) .D1 (alias: Ic displayp)
Display a visible indicator of each pane shown by Display a visible indicator of each pane shown by
@ -1261,8 +1256,7 @@ For the meaning of the
flag, see the flag, see the
.Sx FORMATS .Sx FORMATS
section. section.
This command only works from inside This command works only if at least one client is attached.
.Nm .
.It Xo Ic join-pane .It Xo Ic join-pane
.Op Fl bdhv .Op Fl bdhv
.Oo Fl l .Oo Fl l
@ -3310,8 +3304,7 @@ For the meaning of the
flag, see the flag, see the
.Sx FORMATS .Sx FORMATS
section. section.
This command works only from inside This command works only if at least one client is attached.
.Nm .
.It Ic clear-history Op Fl t Ar target-pane .It Ic clear-history Op Fl t Ar target-pane
.D1 (alias: Ic clearhist ) .D1 (alias: Ic clearhist )
Remove and free the history for the specified pane. Remove and free the history for the specified pane.

6
tmux.h
View File

@ -2204,13 +2204,13 @@ struct window_choose_data *window_choose_data_create (int,
void window_choose_data_free(struct window_choose_data *); void window_choose_data_free(struct window_choose_data *);
void window_choose_data_run(struct window_choose_data *); void window_choose_data_run(struct window_choose_data *);
struct window_choose_data *window_choose_add_window(struct window_pane *, struct window_choose_data *window_choose_add_window(struct window_pane *,
struct cmd_ctx *, struct session *, struct winlink *, struct client *, struct session *, struct winlink *,
const char *, char *, u_int); const char *, char *, u_int);
struct window_choose_data *window_choose_add_session(struct window_pane *, struct window_choose_data *window_choose_add_session(struct window_pane *,
struct cmd_ctx *, struct session *, const char *, struct client *, struct session *, const char *,
char *, u_int); char *, u_int);
struct window_choose_data *window_choose_add_item(struct window_pane *, struct window_choose_data *window_choose_add_item(struct window_pane *,
struct cmd_ctx *, struct winlink *, const char *, struct client *, struct winlink *, const char *,
char *, u_int); char *, u_int);
void window_choose_expand_all(struct window_pane *); void window_choose_expand_all(struct window_pane *);

View File

@ -863,11 +863,10 @@ window_choose_scroll_down(struct window_pane *wp)
} }
struct window_choose_data * struct window_choose_data *
window_choose_add_session(struct window_pane *wp, struct cmd_ctx *ctx, window_choose_add_session(struct window_pane *wp, struct client *c,
struct session *s, const char *template, char *action, u_int idx) struct session *s, const char *template, char *action, u_int idx)
{ {
struct window_choose_data *wcd; struct window_choose_data *wcd;
struct client *c = ctx->curclient;
wcd = window_choose_data_create(TREE_SESSION, c, c->session); wcd = window_choose_data_create(TREE_SESSION, c, c->session);
wcd->idx = s->idx; wcd->idx = s->idx;
@ -887,11 +886,10 @@ window_choose_add_session(struct window_pane *wp, struct cmd_ctx *ctx,
} }
struct window_choose_data * struct window_choose_data *
window_choose_add_item(struct window_pane *wp, struct cmd_ctx *ctx, window_choose_add_item(struct window_pane *wp, struct client *c,
struct winlink *wl, const char *template, char *action, u_int idx) struct winlink *wl, const char *template, char *action, u_int idx)
{ {
struct window_choose_data *wcd; struct window_choose_data *wcd;
struct client *c = ctx->curclient;
char *expanded; char *expanded;
wcd = window_choose_data_create(TREE_OTHER, c, c->session); wcd = window_choose_data_create(TREE_OTHER, c, c->session);
@ -918,12 +916,11 @@ window_choose_add_item(struct window_pane *wp, struct cmd_ctx *ctx,
} }
struct window_choose_data * struct window_choose_data *
window_choose_add_window(struct window_pane *wp, struct cmd_ctx *ctx, window_choose_add_window(struct window_pane *wp, struct client *c,
struct session *s, struct winlink *wl, const char *template, struct session *s, struct winlink *wl, const char *template,
char *action, u_int idx) char *action, u_int idx)
{ {
struct window_choose_data *wcd; struct window_choose_data *wcd;
struct client *c = ctx->curclient;
char *expanded; char *expanded;
wcd = window_choose_data_create(TREE_WINDOW, c, c->session); wcd = window_choose_data_create(TREE_WINDOW, c, c->session);