Get rid of the extra layer of flags and cmd_prepare() and just store the

CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.
This commit is contained in:
nicm 2017-04-22 10:22:39 +00:00
parent 2c0f826c36
commit ee45a8a149
53 changed files with 324 additions and 439 deletions

View File

@ -40,21 +40,23 @@ const struct cmd_entry cmd_attach_session_entry = {
.args = { "c:dErt:", 0, 0 },
.usage = "[-dEr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
.tflag = CMD_SESSION_WITHPANE,
/* -t is special */
.flags = CMD_STARTSERVER,
.exec = cmd_attach_session_exec
};
enum cmd_retval
cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
const char *cflag, int Eflag)
cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
int rflag, const char *cflag, int Eflag)
{
struct cmd_find_state *current = &item->shared->current;
struct session *s = item->state.tflag.s;
enum cmd_find_type type;
int flags;
struct client *c = item->client, *c_loop;
struct winlink *wl = item->state.tflag.wl;
struct window_pane *wp = item->state.tflag.wp;
struct session *s;
struct winlink *wl;
struct window_pane *wp;
char *cause;
if (RB_EMPTY(&sessions)) {
@ -70,6 +72,19 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
return (CMD_RETURN_ERROR);
}
if (tflag != NULL && tflag[strcspn(tflag, ":.")] != '\0') {
type = CMD_FIND_PANE;
flags = 0;
} else {
type = CMD_FIND_SESSION;
flags = CMD_FIND_PREFER_UNATTACHED;
}
if (cmd_find_target(&item->target, item, tflag, type, flags) != 0)
return (CMD_RETURN_ERROR);
s = item->target.s;
wl = item->target.wl;
wp = item->target.wp;
if (wl != NULL) {
if (wp != NULL)
window_set_active_pane(wp->window, wp);
@ -150,6 +165,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
return (cmd_attach_session(item, args_has(args, 'd'),
args_has(args, 'r'), args_get(args, 'c'), args_has(args, 'E')));
return (cmd_attach_session(item, args_get(args, 't'),
args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c'),
args_has(args, 'E')));
}

View File

@ -35,10 +35,11 @@ const struct cmd_entry cmd_break_pane_entry = {
.alias = "breakp",
.args = { "dPF:n:s:t:", 0, 0 },
.usage = "[-dP] [-F format] [-n window-name] [-s src-pane] [-t dst-window]",
.usage = "[-dP] [-F format] [-n window-name] [-s src-pane] "
"[-t dst-window]",
.sflag = CMD_PANE,
.tflag = CMD_WINDOW_INDEX,
.source = { 's', CMD_FIND_PANE, 0 },
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
.flags = 0,
.exec = cmd_break_pane_exec
@ -49,14 +50,14 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct cmd_find_state *current = &item->shared->current;
struct client *c = item->state.c;
struct winlink *wl = item->state.sflag.wl;
struct session *src_s = item->state.sflag.s;
struct session *dst_s = item->state.tflag.s;
struct window_pane *wp = item->state.sflag.wp;
struct client *c = cmd_find_client(item, NULL, 1);
struct winlink *wl = item->source.wl;
struct session *src_s = item->source.s;
struct session *dst_s = item->target.s;
struct window_pane *wp = item->source.wp;
struct window *w = wl->window;
char *name, *cause;
int idx = item->state.tflag.idx;
int idx = item->target.idx;
const char *template;
char *cp;

View File

@ -43,7 +43,7 @@ const struct cmd_entry cmd_capture_pane_entry = {
.usage = "[-aCeJpPq] " CMD_BUFFER_USAGE " [-E end-line] "
"[-S start-line]" CMD_TARGET_PANE_USAGE,
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_capture_pane_exec
@ -56,7 +56,7 @@ const struct cmd_entry cmd_clear_history_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_PANE_USAGE,
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_capture_pane_exec
@ -193,7 +193,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct client *c;
struct window_pane *wp = item->state.tflag.wp;
struct window_pane *wp = item->target.wp;
char *buf, *cause;
const char *bufname;
size_t len;

View File

@ -40,7 +40,7 @@ const struct cmd_entry cmd_choose_buffer_entry = {
.args = { "F:t:", 0, 1 },
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_choose_buffer_exec
@ -50,8 +50,8 @@ static enum cmd_retval
cmd_choose_buffer_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct client *c = item->state.c;
struct winlink *wl = item->state.tflag.wl;
struct client *c = cmd_find_client(item, NULL, 1);
struct winlink *wl = item->target.wl;
struct window_choose_data *cdata;
struct paste_buffer *pb;
char *action, *action_data;

View File

@ -45,7 +45,7 @@ const struct cmd_entry cmd_choose_client_entry = {
.args = { "F:t:", 0, 1 },
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_choose_client_exec
@ -59,10 +59,10 @@ static enum cmd_retval
cmd_choose_client_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct client *c = item->state.c;
struct client *c = cmd_find_client(item, NULL, 1);
struct client *c1;
struct window_choose_data *cdata;
struct winlink *wl = item->state.tflag.wl;
struct winlink *wl = item->target.wl;
const char *template;
char *action;
u_int idx, cur;

View File

@ -51,7 +51,7 @@ const struct cmd_entry cmd_choose_tree_entry = {
.usage = "[-suw] [-b session-template] [-c window template] "
"[-S format] [-W format] " CMD_TARGET_WINDOW_USAGE,
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_choose_tree_exec
@ -64,7 +64,7 @@ const struct cmd_entry cmd_choose_session_entry = {
.args = { "F:t:", 0, 1 },
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_choose_tree_exec
@ -77,7 +77,7 @@ const struct cmd_entry cmd_choose_window_entry = {
.args = { "F:t:", 0, 1 },
.usage = CMD_TARGET_WINDOW_USAGE "[-F format] [template]",
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_choose_tree_exec
@ -87,9 +87,9 @@ static enum cmd_retval
cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct client *c = item->state.c;
struct winlink *wl = item->state.tflag.wl, *wm;
struct session *s = item->state.tflag.s, *s2;
struct client *c = cmd_find_client(item, NULL, 1);
struct winlink *wl = item->target.wl, *wm;
struct session *s = item->target.s, *s2;
struct window_choose_data *wcd = NULL;
const char *ses_template, *win_template;
char *final_win_action, *cur_win_template;

View File

@ -43,8 +43,6 @@ const struct cmd_entry cmd_command_prompt_entry = {
.usage = "[-1Ni] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "
"[template]",
.tflag = CMD_CLIENT,
.flags = 0,
.exec = cmd_command_prompt_exec
};
@ -69,10 +67,13 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
struct args *args = self->args;
const char *inputs, *prompts;
struct cmd_command_prompt_cdata *cdata;
struct client *c = item->state.c;
struct client *c;
char *prompt, *ptr, *input = NULL;
size_t n;
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if (c->prompt_string != NULL)
return (CMD_RETURN_NORMAL);

View File

@ -41,8 +41,6 @@ const struct cmd_entry cmd_confirm_before_entry = {
.args = { "p:t:", 1, 1 },
.usage = "[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
.tflag = CMD_CLIENT,
.flags = 0,
.exec = cmd_confirm_before_exec
};
@ -57,10 +55,13 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct cmd_confirm_before_data *cdata;
struct client *c = item->state.c;
struct client *c;
char *cmd, *copy, *new_prompt, *ptr;
const char *prompt;
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if ((prompt = args_get(args, 'p')) != NULL)
xasprintf(&new_prompt, "%s ", prompt);
else {

View File

@ -33,7 +33,7 @@ const struct cmd_entry cmd_copy_mode_entry = {
.args = { "Met:u", 0, 0 },
.usage = "[-Mu] " CMD_TARGET_PANE_USAGE,
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_copy_mode_exec
@ -46,7 +46,7 @@ const struct cmd_entry cmd_clock_mode_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_PANE_USAGE,
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_copy_mode_exec
@ -59,7 +59,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
struct cmdq_shared *shared = item->shared;
struct client *c = item->client;
struct session *s;
struct window_pane *wp = item->state.tflag.wp;
struct window_pane *wp = item->target.wp;
if (args_has(args, 'M')) {
if ((wp = cmd_mouse_pane(&shared->mouse, &s, NULL)) == NULL)

View File

@ -37,8 +37,7 @@ const struct cmd_entry cmd_detach_client_entry = {
.usage = "[-aP] [-E shell-command] "
"[-s target-session] " CMD_TARGET_CLIENT_USAGE,
.sflag = CMD_SESSION,
.tflag = CMD_CLIENT,
.source = { 's', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
.flags = CMD_READONLY,
.exec = cmd_detach_client_exec
@ -51,8 +50,6 @@ const struct cmd_entry cmd_suspend_client_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_CLIENT_USAGE,
.tflag = CMD_CLIENT,
.flags = 0,
.exec = cmd_detach_client_exec
};
@ -61,11 +58,14 @@ static enum cmd_retval
cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct client *c = item->state.c, *cloop;
struct client *c, *cloop;
struct session *s;
enum msgtype msgtype;
const char *cmd = args_get(args, 'E');
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if (self->entry == &cmd_suspend_client_entry) {
server_client_suspend(c);
return (CMD_RETURN_NORMAL);
@ -77,7 +77,9 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
msgtype = MSG_DETACH;
if (args_has(args, 's')) {
s = item->state.sflag.s;
s = item->source.s;
if (s == NULL)
return (CMD_RETURN_NORMAL);
TAILQ_FOREACH(cloop, &clients, entry) {
if (cloop->session == s) {
if (cmd != NULL)

View File

@ -43,8 +43,7 @@ const struct cmd_entry cmd_display_message_entry = {
.usage = "[-p] [-c target-client] [-F format] "
CMD_TARGET_PANE_USAGE " [message]",
.cflag = CMD_CLIENT_CANFAIL,
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_display_message_exec
@ -54,10 +53,10 @@ static enum cmd_retval
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct client *c = item->state.c;
struct session *s = item->state.tflag.s;
struct winlink *wl = item->state.tflag.wl;
struct window_pane *wp = item->state.tflag.wp;
struct client *c;
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct window_pane *wp = item->target.wp;
const char *template;
char *msg;
struct format_tree *ft;
@ -66,6 +65,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
cmdq_error(item, "only one of -F or argument must be given");
return (CMD_RETURN_ERROR);
}
c = cmd_find_client(item, args_get(args, 'c'), 1);
template = args_get(args, 'F');
if (args->argc != 0)

View File

@ -40,8 +40,6 @@ const struct cmd_entry cmd_display_panes_entry = {
.args = { "t:", 0, 1 },
.usage = CMD_TARGET_CLIENT_USAGE,
.tflag = CMD_CLIENT,
.flags = CMD_AFTERHOOK,
.exec = cmd_display_panes_exec
};
@ -50,7 +48,10 @@ static enum cmd_retval
cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct client *c = item->state.c;
struct client *c;
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if (c->identify_callback != NULL)
return (CMD_RETURN_NORMAL);

View File

@ -54,7 +54,7 @@ const struct cmd_entry cmd_find_window_entry = {
.args = { "F:CNt:T", 1, 4 },
.usage = "[-CNT] [-F format] " CMD_TARGET_WINDOW_USAGE " match-string",
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_find_window_exec
@ -143,10 +143,10 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct cmd_find_state *current = &item->shared->current;
struct client *c = item->state.c;
struct client *c = cmd_find_client(item, NULL, 1);
struct window_choose_data *cdata;
struct session *s = item->state.tflag.s;
struct winlink *wl = item->state.tflag.wl, *wm;
struct session *s = item->target.s;
struct winlink *wl = item->target.wl, *wm;
struct cmd_find_window_list find_list;
struct cmd_find_window_data *find_data;
struct cmd_find_window_data *find_data1;

View File

@ -953,6 +953,10 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
const char *session, *window, *pane;
int window_only = 0, pane_only = 0;
/* Can fail flag implies quiet. */
if (flags & CMD_FIND_CANFAIL)
flags |= CMD_FIND_QUIET;
/* Log the arguments. */
if (target == NULL)
log_debug("%s: target none, type %d", __func__, type);
@ -1190,6 +1194,8 @@ error:
log_debug("%s: error", __func__);
free(copy);
if (flags & CMD_FIND_CANFAIL)
return (0);
return (-1);
found:

View File

@ -43,7 +43,7 @@ const struct cmd_entry cmd_if_shell_entry = {
.usage = "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command "
"[command]",
.tflag = CMD_PANE_CANFAIL,
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
.flags = 0,
.exec = cmd_if_shell_exec
@ -70,10 +70,10 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
char *shellcmd, *cmd, *cause;
struct cmd_list *cmdlist;
struct cmdq_item *new_item;
struct client *c = item->state.c;
struct session *s = item->state.tflag.s;
struct winlink *wl = item->state.tflag.wl;
struct window_pane *wp = item->state.tflag.wp;
struct client *c = cmd_find_client(item, NULL, 1);
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct window_pane *wp = item->target.wp;
const char *cwd;
if (item->client != NULL && item->client->session == NULL)

View File

@ -38,8 +38,8 @@ const struct cmd_entry cmd_join_pane_entry = {
.args = { "bdhvp:l:s:t:", 0, 0 },
.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
.sflag = CMD_PANE_MARKED,
.tflag = CMD_PANE,
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
.target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_join_pane_exec
@ -52,8 +52,8 @@ const struct cmd_entry cmd_move_pane_entry = {
.args = { "bdhvp:l:s:t:", 0, 0 },
.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
.sflag = CMD_PANE,
.tflag = CMD_PANE,
.source = { 's', CMD_FIND_PANE, 0 },
.target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_join_pane_exec
@ -79,15 +79,15 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
else
not_same_window = 0;
dst_s = item->state.tflag.s;
dst_wl = item->state.tflag.wl;
dst_wp = item->state.tflag.wp;
dst_s = item->target.s;
dst_wl = item->target.wl;
dst_wp = item->target.wp;
dst_w = dst_wl->window;
dst_idx = dst_wl->idx;
server_unzoom_window(dst_w);
src_wl = item->state.sflag.wl;
src_wp = item->state.sflag.wp;
src_wl = item->source.wl;
src_wp = item->source.wp;
src_w = src_wl->window;
server_unzoom_window(src_w);

View File

@ -35,7 +35,7 @@ const struct cmd_entry cmd_kill_pane_entry = {
.args = { "at:", 0, 0 },
.usage = "[-a] " CMD_TARGET_PANE_USAGE,
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_kill_pane_exec
@ -44,8 +44,8 @@ const struct cmd_entry cmd_kill_pane_entry = {
static enum cmd_retval
cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct winlink *wl = item->state.tflag.wl;
struct window_pane *loopwp, *tmpwp, *wp = item->state.tflag.wp;
struct winlink *wl = item->target.wl;
struct window_pane *loopwp, *tmpwp, *wp = item->target.wp;
server_unzoom_window(wl->window);

View File

@ -36,7 +36,7 @@ const struct cmd_entry cmd_kill_session_entry = {
.args = { "aCt:", 0, 0 },
.usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
.tflag = CMD_SESSION,
.target = { 't', CMD_FIND_SESSION, 0 },
.flags = 0,
.exec = cmd_kill_session_exec
@ -49,7 +49,7 @@ cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
struct session *s, *sloop, *stmp;
struct winlink *wl;
s = item->state.tflag.s;
s = item->target.s;
if (args_has(args, 'C')) {
RB_FOREACH(wl, winlinks, &s->windows) {

View File

@ -33,7 +33,7 @@ const struct cmd_entry cmd_kill_window_entry = {
.args = { "at:", 0, 0 },
.usage = "[-a] " CMD_TARGET_WINDOW_USAGE,
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_kill_window_exec
@ -46,7 +46,7 @@ const struct cmd_entry cmd_unlink_window_entry = {
.args = { "kt:", 0, 0 },
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE,
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_kill_window_exec
@ -56,9 +56,9 @@ static enum cmd_retval
cmd_kill_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct winlink *wl = item->state.tflag.wl, *wl2, *wl3;
struct winlink *wl = item->target.wl, *wl2, *wl3;
struct window *w = wl->window;
struct session *s = item->state.tflag.s;
struct session *s = item->target.s;
if (self->entry == &cmd_unlink_window_entry) {
if (!args_has(self->args, 'k') && !session_is_linked(s, w)) {

View File

@ -42,7 +42,7 @@ const struct cmd_entry cmd_list_clients_entry = {
.args = { "F:t:", 0, 0 },
.usage = "[-F format] " CMD_TARGET_SESSION_USAGE,
.tflag = CMD_SESSION,
.target = { 't', CMD_FIND_SESSION, 0 },
.flags = CMD_READONLY|CMD_AFTERHOOK,
.exec = cmd_list_clients_exec
@ -60,7 +60,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
char *line;
if (args_has(args, 't'))
s = item->state.tflag.s;
s = item->target.s;
else
s = NULL;

View File

@ -41,7 +41,7 @@ const struct cmd_entry cmd_list_panes_entry = {
.args = { "asF:t:", 0, 0 },
.usage = "[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_list_panes_exec
@ -51,8 +51,8 @@ static enum cmd_retval
cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct session *s = item->state.tflag.s;
struct winlink *wl = item->state.tflag.wl;
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
if (args_has(args, 'a'))
cmd_list_panes_server(self, item);

View File

@ -52,7 +52,7 @@ const struct cmd_entry cmd_list_windows_entry = {
.args = { "F:at:", 0, 0 },
.usage = "[-a] [-F format] " CMD_TARGET_SESSION_USAGE,
.tflag = CMD_SESSION,
.target = { 't', CMD_FIND_SESSION, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_list_windows_exec
@ -66,7 +66,7 @@ cmd_list_windows_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'a'))
cmd_list_windows_server(self, item);
else
cmd_list_windows_session(self, item->state.tflag.s, item, 0);
cmd_list_windows_session(self, item->target.s, item, 0);
return (CMD_RETURN_NORMAL);
}

View File

@ -44,7 +44,7 @@ const struct cmd_entry cmd_lock_session_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_SESSION_USAGE,
.tflag = CMD_SESSION,
.target = { 't', CMD_FIND_SESSION, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_lock_server_exec
@ -57,22 +57,25 @@ const struct cmd_entry cmd_lock_client_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_CLIENT_USAGE,
.tflag = CMD_CLIENT,
.flags = CMD_AFTERHOOK,
.exec = cmd_lock_server_exec
};
static enum cmd_retval
cmd_lock_server_exec(struct cmd *self, __unused struct cmdq_item *item)
cmd_lock_server_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct client *c;
if (self->entry == &cmd_lock_server_entry)
server_lock();
else if (self->entry == &cmd_lock_session_entry)
server_lock_session(item->state.tflag.s);
else
server_lock_client(item->state.c);
server_lock_session(item->target.s);
else {
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
server_lock_client(c);
}
recalculate_sizes();
return (CMD_RETURN_NORMAL);

View File

@ -35,8 +35,8 @@ const struct cmd_entry cmd_move_window_entry = {
.args = { "adkrs:t:", 0, 0 },
.usage = "[-dkr] " CMD_SRCDST_WINDOW_USAGE,
.sflag = CMD_WINDOW,
.tflag = CMD_MOVEW_R,
.source = { 's', CMD_FIND_WINDOW, 0 },
/* -t is special */
.flags = 0,
.exec = cmd_move_window_exec
@ -49,8 +49,8 @@ const struct cmd_entry cmd_link_window_entry = {
.args = { "adks:t:", 0, 0 },
.usage = "[-dk] " CMD_SRCDST_WINDOW_USAGE,
.sflag = CMD_WINDOW,
.tflag = CMD_WINDOW_INDEX,
.source = { 's', CMD_FIND_WINDOW, 0 },
/* -t is special */
.flags = 0,
.exec = cmd_move_window_exec
@ -60,18 +60,31 @@ static enum cmd_retval
cmd_move_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct session *src = item->state.sflag.s;
struct session *dst = item->state.tflag.s;
struct winlink *wl = item->state.sflag.wl;
const char *tflag = args_get(args, 't');
struct session *src;
struct session *dst;
struct winlink *wl;
char *cause;
int idx = item->state.tflag.idx, kflag, dflag, sflag;
int idx, kflag, dflag, sflag;
if (args_has(args, 'r')) {
session_renumber_windows(dst);
if (cmd_find_target(&item->target, item, tflag,
CMD_FIND_SESSION, CMD_FIND_QUIET) != 0)
return (CMD_RETURN_ERROR);
session_renumber_windows(item->target.s);
recalculate_sizes();
server_status_session(item->target.s);
return (CMD_RETURN_NORMAL);
}
if (cmd_find_target(&item->target, item, tflag, CMD_FIND_WINDOW,
CMD_FIND_WINDOW_INDEX) != 0)
return (CMD_RETURN_ERROR);
src = item->source.s;
dst = item->target.s;
wl = item->source.wl;
idx = item->target.idx;
kflag = args_has(self->args, 'k');
dflag = args_has(self->args, 'd');

View File

@ -44,7 +44,7 @@ const struct cmd_entry cmd_new_session_entry = {
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
"[-y height] [command]",
.tflag = CMD_SESSION_CANFAIL,
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
.flags = CMD_STARTSERVER,
.exec = cmd_new_session_exec
@ -57,7 +57,7 @@ const struct cmd_entry cmd_has_session_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_SESSION_USAGE,
.tflag = CMD_SESSION,
.target = { 't', CMD_FIND_SESSION, 0 },
.flags = 0,
.exec = cmd_new_session_exec
@ -108,10 +108,10 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
* have already been prepared, copy this
* session into its tflag so it can be used.
*/
cmd_find_from_session(&item->state.tflag, as);
cmd_find_from_session(&item->target, as);
return (cmd_attach_session(item,
args_has(args, 'D'), 0, NULL,
args_has(args, 'E')));
args_get(args, 't'), args_has(args, 'D'),
0, NULL, args_has(args, 'E')));
}
cmdq_error(item, "duplicate session: %s", newname);
return (CMD_RETURN_ERROR);
@ -121,7 +121,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
/* Is this going to be part of a session group? */
group = args_get(args, 't');
if (group != NULL) {
groupwith = item->state.tflag.s;
groupwith = item->target.s;
if (groupwith == NULL) {
if (!session_check_name(group)) {
cmdq_error(item, "bad group name: %s", group);

View File

@ -42,7 +42,7 @@ const struct cmd_entry cmd_new_window_entry = {
.usage = "[-adkP] [-c start-directory] [-F format] [-n window-name] "
CMD_TARGET_WINDOW_USAGE " [command]",
.tflag = CMD_WINDOW_INDEX,
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
.flags = 0,
.exec = cmd_new_window_exec
@ -53,10 +53,10 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct cmd_find_state *current = &item->shared->current;
struct session *s = item->state.tflag.s;
struct winlink *wl = item->state.tflag.wl;
struct client *c = item->state.c;
int idx = item->state.tflag.idx;
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct client *c = cmd_find_client(item, NULL, 1);
int idx = item->target.idx;
const char *cmd, *path, *template, *cwd, *to_free;
char **argv, *cause, *cp;
int argc, detached;

View File

@ -38,7 +38,7 @@ const struct cmd_entry cmd_paste_buffer_entry = {
.usage = "[-dpr] [-s separator] " CMD_BUFFER_USAGE " "
CMD_TARGET_PANE_USAGE,
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_paste_buffer_exec
@ -48,7 +48,7 @@ static enum cmd_retval
cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct window_pane *wp = item->state.tflag.wp;
struct window_pane *wp = item->target.wp;
struct paste_buffer *pb;
const char *sepstr, *bufname, *bufdata, *bufend, *line;
size_t seplen, bufsize;

View File

@ -44,7 +44,7 @@ const struct cmd_entry cmd_pipe_pane_entry = {
.args = { "ot:", 0, 1 },
.usage = "[-o] " CMD_TARGET_PANE_USAGE " [command]",
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_pipe_pane_exec
@ -54,10 +54,10 @@ static enum cmd_retval
cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct client *c = item->state.c;
struct window_pane *wp = item->state.tflag.wp;
struct session *s = item->state.tflag.s;
struct winlink *wl = item->state.tflag.wl;
struct client *c = cmd_find_client(item, NULL, 1);
struct window_pane *wp = item->target.wp;
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
char *cmd;
int old_fd, pipe_fd[2], null_fd;
struct format_tree *ft;

View File

@ -189,14 +189,34 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
return (first);
}
/* Fill in flag for a command. */
static enum cmd_retval
cmdq_find_flag(struct cmdq_item *item, struct cmd_find_state *fs,
const struct cmd_entry_flag *flag)
{
const char *value;
if (flag->flag == 0) {
cmd_find_clear_state(fs, 0);
return (CMD_RETURN_NORMAL);
}
value = args_get(item->cmd->args, flag->flag);
if (cmd_find_target(fs, item, value, flag->type, flag->flags) != 0) {
cmd_find_clear_state(fs, 0);
return (CMD_RETURN_ERROR);
}
return (CMD_RETURN_NORMAL);
}
/* Fire command on command queue. */
static enum cmd_retval
cmdq_fire_command(struct cmdq_item *item)
{
struct client *c = item->client;
struct cmd *cmd = item->cmd;
const struct cmd_entry *entry = cmd->entry;
enum cmd_retval retval;
const char *name;
struct cmd_find_state *fsp, fs;
int flags;
@ -205,27 +225,27 @@ cmdq_fire_command(struct cmdq_item *item)
if (item->client == NULL)
item->client = cmd_find_client(item, NULL, 1);
if (cmd_prepare_state(cmd, item) != 0) {
retval = CMD_RETURN_ERROR;
retval = cmdq_find_flag(item, &item->source, &entry->source);
if (retval == CMD_RETURN_ERROR)
goto out;
}
retval = cmd->entry->exec(cmd, item);
retval = cmdq_find_flag(item, &item->target, &entry->target);
if (retval == CMD_RETURN_ERROR)
goto out;
if (cmd->entry->flags & CMD_AFTERHOOK) {
name = cmd->entry->name;
if (cmd_find_valid_state(&item->state.tflag))
fsp = &item->state.tflag;
retval = entry->exec(cmd, item);
if (retval == CMD_RETURN_ERROR)
goto out;
if (entry->flags & CMD_AFTERHOOK) {
if (cmd_find_valid_state(&item->target))
fsp = &item->target;
else if (cmd_find_valid_state(&item->shared->current))
fsp = &item->shared->current;
else if (cmd_find_from_client(&fs, item->client) == 0)
fsp = &fs;
else
goto out;
hooks_insert(fsp->s->hooks, item, fsp, "after-%s", name);
hooks_insert(fsp->s->hooks, item, fsp, "after-%s", entry->name);
}
out:

View File

@ -34,8 +34,6 @@ const struct cmd_entry cmd_refresh_client_entry = {
.args = { "C:St:", 0, 0 },
.usage = "[-S] [-C size] " CMD_TARGET_CLIENT_USAGE,
.tflag = CMD_CLIENT,
.flags = CMD_AFTERHOOK,
.exec = cmd_refresh_client_exec
};
@ -44,10 +42,13 @@ static enum cmd_retval
cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct client *c = item->state.c;
struct client *c;
const char *size;
u_int w, h;
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, 'C')) {
if ((size = args_get(args, 'C')) == NULL) {
cmdq_error(item, "missing size");

View File

@ -37,7 +37,7 @@ const struct cmd_entry cmd_rename_session_entry = {
.args = { "t:", 1, 1 },
.usage = CMD_TARGET_SESSION_USAGE " new-name",
.tflag = CMD_SESSION,
.target = { 't', CMD_FIND_SESSION, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_rename_session_exec
@ -47,7 +47,7 @@ static enum cmd_retval
cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct session *s = item->state.tflag.s;
struct session *s = item->target.s;
const char *newname;
newname = args->argv[0];

View File

@ -36,7 +36,7 @@ const struct cmd_entry cmd_rename_window_entry = {
.args = { "t:", 1, 1 },
.usage = CMD_TARGET_WINDOW_USAGE " new-name",
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_rename_window_exec
@ -46,7 +46,7 @@ static enum cmd_retval
cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct winlink *wl = item->state.tflag.wl;
struct winlink *wl = item->target.wl;
window_set_name(wl->window, args->argv[0]);
options_set_number(wl->window->options, "automatic-rename", 0);

View File

@ -39,7 +39,7 @@ const struct cmd_entry cmd_resize_pane_entry = {
.usage = "[-DLMRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
"[adjustment]",
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_resize_pane_exec
@ -50,11 +50,11 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct cmdq_shared *shared = item->shared;
struct window_pane *wp = item->state.tflag.wp;
struct winlink *wl = item->state.tflag.wl;
struct window_pane *wp = item->target.wp;
struct winlink *wl = item->target.wl;
struct window *w = wl->window;
struct client *c = item->client;
struct session *s = item->state.tflag.s;
struct session *s = item->target.s;
const char *errstr;
char *cause;
u_int adjust;

View File

@ -37,7 +37,7 @@ const struct cmd_entry cmd_respawn_pane_entry = {
.args = { "kt:", 0, -1 },
.usage = "[-k] " CMD_TARGET_PANE_USAGE " [command]",
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_respawn_pane_exec
@ -47,10 +47,10 @@ static enum cmd_retval
cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct winlink *wl = item->state.tflag.wl;
struct winlink *wl = item->target.wl;
struct window *w = wl->window;
struct window_pane *wp = item->state.tflag.wp;
struct session *s = item->state.tflag.s;
struct window_pane *wp = item->target.wp;
struct session *s = item->target.s;
struct environ *env;
const char *path;
char *cause;

View File

@ -37,7 +37,7 @@ const struct cmd_entry cmd_respawn_window_entry = {
.args = { "kt:", 0, -1 },
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_respawn_window_exec
@ -47,8 +47,8 @@ static enum cmd_retval
cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct session *s = item->state.tflag.s;
struct winlink *wl = item->state.tflag.wl;
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct window *w = wl->window;
struct window_pane *wp;
struct environ *env;

View File

@ -34,7 +34,7 @@ const struct cmd_entry cmd_rotate_window_entry = {
.args = { "Dt:U", 0, 0 },
.usage = "[-DU] " CMD_TARGET_WINDOW_USAGE,
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_rotate_window_exec
@ -43,7 +43,7 @@ const struct cmd_entry cmd_rotate_window_entry = {
static enum cmd_retval
cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct winlink *wl = item->state.tflag.wl;
struct winlink *wl = item->target.wl;
struct window *w = wl->window;
struct window_pane *wp, *wp2;
struct layout_cell *lc;

View File

@ -42,7 +42,7 @@ const struct cmd_entry cmd_run_shell_entry = {
.args = { "bt:", 1, 1 },
.usage = "[-b] " CMD_TARGET_PANE_USAGE " shell-command",
.tflag = CMD_PANE_CANFAIL,
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
.flags = 0,
.exec = cmd_run_shell_exec
@ -86,10 +86,10 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct cmd_run_shell_data *cdata;
struct client *c = item->state.c;
struct session *s = item->state.tflag.s;
struct winlink *wl = item->state.tflag.wl;
struct window_pane *wp = item->state.tflag.wp;
struct client *c = cmd_find_client(item, NULL, 1);
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct window_pane *wp = item->target.wp;
const char *cwd;
if (item->client != NULL && item->client->session == NULL)

View File

@ -36,7 +36,7 @@ const struct cmd_entry cmd_select_layout_entry = {
.args = { "nopt:", 0, 1 },
.usage = "[-nop] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_select_layout_exec
@ -49,7 +49,7 @@ const struct cmd_entry cmd_next_layout_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_WINDOW_USAGE,
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_select_layout_exec
@ -62,7 +62,7 @@ const struct cmd_entry cmd_previous_layout_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_WINDOW_USAGE,
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_select_layout_exec
@ -72,7 +72,7 @@ static enum cmd_retval
cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct winlink *wl = item->state.tflag.wl;
struct winlink *wl = item->target.wl;
struct window *w;
const char *layoutname;
char *oldlayout;

View File

@ -33,7 +33,7 @@ const struct cmd_entry cmd_select_pane_entry = {
.args = { "DdegLlMmP:Rt:U", 0, 0 },
.usage = "[-DdegLlMmRU] [-P style] " CMD_TARGET_PANE_USAGE,
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_select_pane_exec
@ -46,7 +46,7 @@ const struct cmd_entry cmd_last_pane_entry = {
.args = { "det:", 0, 0 },
.usage = "[-de] " CMD_TARGET_WINDOW_USAGE,
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_select_pane_exec
@ -57,10 +57,10 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct cmd_find_state *current = &item->shared->current;
struct winlink *wl = item->state.tflag.wl;
struct winlink *wl = item->target.wl;
struct window *w = wl->window;
struct session *s = item->state.tflag.s;
struct window_pane *wp = item->state.tflag.wp, *lastwp, *markedwp;
struct session *s = item->target.s;
struct window_pane *wp = item->target.wp, *lastwp, *markedwp;
const char *style;
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {

View File

@ -36,7 +36,7 @@ const struct cmd_entry cmd_select_window_entry = {
.args = { "lnpTt:", 0, 0 },
.usage = "[-lnpT] " CMD_TARGET_WINDOW_USAGE,
.tflag = CMD_WINDOW,
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_select_window_exec
@ -49,7 +49,7 @@ const struct cmd_entry cmd_next_window_entry = {
.args = { "at:", 0, 0 },
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
.tflag = CMD_SESSION,
.target = { 't', CMD_FIND_SESSION, 0 },
.flags = 0,
.exec = cmd_select_window_exec
@ -62,7 +62,7 @@ const struct cmd_entry cmd_previous_window_entry = {
.args = { "at:", 0, 0 },
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
.tflag = CMD_SESSION,
.target = { 't', CMD_FIND_SESSION, 0 },
.flags = 0,
.exec = cmd_select_window_exec
@ -75,7 +75,7 @@ const struct cmd_entry cmd_last_window_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_SESSION_USAGE,
.tflag = CMD_SESSION,
.target = { 't', CMD_FIND_SESSION, 0 },
.flags = 0,
.exec = cmd_select_window_exec
@ -85,8 +85,8 @@ static enum cmd_retval
cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct cmd_find_state *current = &item->shared->current;
struct winlink *wl = item->state.tflag.wl;
struct session *s = item->state.tflag.s;
struct winlink *wl = item->target.wl;
struct session *s = item->target.s;
int next, previous, last, activity;
next = self->entry == &cmd_next_window_entry;

View File

@ -36,7 +36,7 @@ const struct cmd_entry cmd_send_keys_entry = {
.args = { "lXRMN:t:", 0, -1 },
.usage = "[-lXRM] [-N repeat-count] " CMD_TARGET_PANE_USAGE " key ...",
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_send_keys_exec
@ -49,7 +49,7 @@ const struct cmd_entry cmd_send_prefix_entry = {
.args = { "2t:", 0, 0 },
.usage = "[-2] " CMD_TARGET_PANE_USAGE,
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_send_keys_exec
@ -59,9 +59,9 @@ static enum cmd_retval
cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct client *c = item->state.c;
struct window_pane *wp = item->state.tflag.wp;
struct session *s = item->state.tflag.s;
struct client *c = cmd_find_client(item, NULL, 1);
struct window_pane *wp = item->target.wp;
struct session *s = item->target.s;
struct mouse_event *m = &item->shared->mouse;
struct utf8_data *ud, *uc;
wchar_t wc;

View File

@ -37,7 +37,7 @@ const struct cmd_entry cmd_set_environment_entry = {
.args = { "grt:u", 1, 2 },
.usage = "[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
.tflag = CMD_SESSION_CANFAIL,
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_set_environment_exec
@ -68,7 +68,7 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(self->args, 'g'))
env = global_environ;
else {
if (item->state.tflag.s == NULL) {
if (item->target.s == NULL) {
target = args_get(args, 't');
if (target != NULL)
cmdq_error(item, "no such session: %s", target);
@ -76,7 +76,7 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR);
}
env = item->state.tflag.s->environ;
env = item->target.s->environ;
}
if (args_has(self->args, 'u')) {

View File

@ -36,7 +36,7 @@ const struct cmd_entry cmd_set_hook_entry = {
.args = { "gt:u", 1, 2 },
.usage = "[-gu] " CMD_TARGET_SESSION_USAGE " hook-name [command]",
.tflag = CMD_SESSION_CANFAIL,
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_set_hook_exec
@ -49,7 +49,7 @@ const struct cmd_entry cmd_show_hooks_entry = {
.args = { "gt:", 0, 1 },
.usage = "[-g] " CMD_TARGET_SESSION_USAGE,
.tflag = CMD_SESSION,
.target = { 't', CMD_FIND_SESSION, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_set_hook_exec
@ -68,7 +68,7 @@ cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'g'))
hooks = global_hooks;
else {
if (item->state.tflag.s == NULL) {
if (item->target.s == NULL) {
target = args_get(args, 't');
if (target != NULL)
cmdq_error(item, "no such session: %s", target);
@ -76,7 +76,7 @@ cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item)
cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR);
}
hooks = item->state.tflag.s->hooks;
hooks = item->target.s->hooks;
}
if (self->entry == &cmd_show_hooks_entry) {

View File

@ -45,7 +45,7 @@ const struct cmd_entry cmd_set_option_entry = {
.args = { "agoqst:uw", 1, 2 },
.usage = "[-agosquw] [-t target-window] option [value]",
.tflag = CMD_WINDOW_CANFAIL,
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_set_option_exec
@ -58,7 +58,7 @@ const struct cmd_entry cmd_set_window_option_entry = {
.args = { "agoqt:u", 1, 2 },
.usage = "[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
.tflag = CMD_WINDOW_CANFAIL,
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_set_option_exec
@ -69,7 +69,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
int append = args_has(args, 'a');
struct cmd_find_state *fs = &item->state.tflag;
struct cmd_find_state *fs = &item->target;
struct session *s = fs->s;
struct winlink *wl = fs->wl;
struct window *w;

View File

@ -41,7 +41,7 @@ const struct cmd_entry cmd_show_environment_entry = {
.args = { "gst:", 0, 1 },
.usage = "[-gs] " CMD_TARGET_SESSION_USAGE " [name]",
.tflag = CMD_SESSION_CANFAIL,
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_show_environment_exec
@ -97,7 +97,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item)
const char *target;
if ((target = args_get(args, 't')) != NULL) {
if (item->state.tflag.s == NULL) {
if (item->target.s == NULL) {
cmdq_error(item, "no such session: %s", target);
return (CMD_RETURN_ERROR);
}
@ -106,7 +106,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(self->args, 'g'))
env = global_environ;
else {
if (item->state.tflag.s == NULL) {
if (item->target.s == NULL) {
target = args_get(args, 't');
if (target != NULL)
cmdq_error(item, "no such session: %s", target);
@ -114,7 +114,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item)
cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR);
}
env = item->state.tflag.s->environ;
env = item->target.s->environ;
}
if (args->argc != 0) {

View File

@ -39,8 +39,6 @@ const struct cmd_entry cmd_show_messages_entry = {
.args = { "JTt:", 0, 0 },
.usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
.tflag = CMD_CLIENT,
.flags = CMD_AFTERHOOK,
.exec = cmd_show_messages_exec
};
@ -92,11 +90,14 @@ static enum cmd_retval
cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct client *c = item->state.c;
struct client *c;
struct message_entry *msg;
char *tim;
int done, blank;
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
done = blank = 0;
if (args_has(args, 'T')) {
blank = cmd_show_messages_terminals(item, blank);

View File

@ -42,7 +42,7 @@ const struct cmd_entry cmd_show_options_entry = {
.args = { "gqst:vw", 0, 1 },
.usage = "[-gqsvw] [-t target-session|target-window] [option]",
.tflag = CMD_WINDOW_CANFAIL,
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_show_options_exec
@ -55,7 +55,7 @@ const struct cmd_entry cmd_show_window_options_entry = {
.args = { "gvt:", 0, 1 },
.usage = "[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
.tflag = CMD_WINDOW_CANFAIL,
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_show_options_exec
@ -65,7 +65,7 @@ static enum cmd_retval
cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct cmd_find_state *fs = &item->state.tflag;
struct cmd_find_state *fs = &item->target;
struct options *oo;
enum options_table_scope scope;
char *cause;

View File

@ -44,7 +44,7 @@ const struct cmd_entry cmd_split_window_entry = {
.usage = "[-bdfhvP] [-c start-directory] [-F format] "
"[-p percentage|-l size] " CMD_TARGET_PANE_USAGE " [command]",
.tflag = CMD_PANE,
.target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_split_window_exec
@ -55,11 +55,11 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct cmd_find_state *current = &item->shared->current;
struct args *args = self->args;
struct client *c = item->state.c;
struct session *s = item->state.tflag.s;
struct winlink *wl = item->state.tflag.wl;
struct client *c = cmd_find_client(item, NULL, 1);
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
struct window *w = wl->window;
struct window_pane *wp = item->state.tflag.wp, *new_wp = NULL;
struct window_pane *wp = item->target.wp, *new_wp = NULL;
struct environ *env;
const char *cmd, *path, *shell, *template, *cwd, *to_free;
char **argv, *cause, *new_cause, *cp;

View File

@ -35,8 +35,8 @@ const struct cmd_entry cmd_swap_pane_entry = {
.args = { "dDs:t:U", 0, 0 },
.usage = "[-dDU] " CMD_SRCDST_PANE_USAGE,
.sflag = CMD_PANE_MARKED,
.tflag = CMD_PANE,
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
.target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_swap_pane_exec
@ -50,10 +50,10 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
struct layout_cell *src_lc, *dst_lc;
u_int sx, sy, xoff, yoff;
dst_w = item->state.tflag.wl->window;
dst_wp = item->state.tflag.wp;
src_w = item->state.sflag.wl->window;
src_wp = item->state.sflag.wp;
dst_w = item->target.wl->window;
dst_wp = item->target.wp;
src_w = item->source.wl->window;
src_wp = item->source.wp;
server_unzoom_window(dst_w);
if (args_has(self->args, 'D')) {

View File

@ -35,8 +35,8 @@ const struct cmd_entry cmd_swap_window_entry = {
.args = { "ds:t:", 0, 0 },
.usage = "[-d] " CMD_SRCDST_WINDOW_USAGE,
.sflag = CMD_WINDOW_MARKED,
.tflag = CMD_WINDOW,
.source = { 's', CMD_FIND_WINDOW, CMD_FIND_DEFAULT_MARKED },
.target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_swap_window_exec
@ -50,12 +50,12 @@ cmd_swap_window_exec(struct cmd *self, struct cmdq_item *item)
struct winlink *wl_src, *wl_dst;
struct window *w_src, *w_dst;
wl_src = item->state.sflag.wl;
src = item->state.sflag.s;
wl_src = item->source.wl;
src = item->source.s;
sg_src = session_group_contains(src);
wl_dst = item->state.tflag.wl;
dst = item->state.tflag.s;
wl_dst = item->target.wl;
dst = item->target.s;
sg_dst = session_group_contains(dst);
if (src != dst && sg_src != NULL && sg_dst != NULL &&

View File

@ -38,8 +38,7 @@ const struct cmd_entry cmd_switch_client_entry = {
.usage = "[-Elnpr] [-c target-client] [-t target-session] "
"[-T key-table]",
.cflag = CMD_CLIENT,
.tflag = CMD_SESSION_WITHPANE,
/* -t is special */
.flags = CMD_READONLY,
.exec = cmd_switch_client_exec
@ -49,13 +48,32 @@ static enum cmd_retval
cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct cmd_state *state = &item->state;
struct client *c = state->c;
struct session *s = item->state.tflag.s;
const char *tflag = args_get(args, 't');
enum cmd_find_type type;
int flags;
struct client *c;
struct session *s;
struct winlink *wl;
struct window_pane *wp;
const char *tablename;
struct key_table *table;
if ((c = cmd_find_client(item, args_get(args, 'c'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if (tflag != NULL && tflag[strcspn(tflag, ":.")] != '\0') {
type = CMD_FIND_PANE;
flags = 0;
} else {
type = CMD_FIND_SESSION;
flags = CMD_FIND_PREFER_UNATTACHED;
}
if (cmd_find_target(&item->target, item, tflag, type, flags) != 0)
return (CMD_RETURN_ERROR);
s = item->target.s;
wl = item->target.wl;
wp = item->target.wp;
if (args_has(args, 'r'))
c->flags ^= CLIENT_READONLY;
@ -94,11 +112,10 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
} else {
if (item->client == NULL)
return (CMD_RETURN_NORMAL);
if (state->tflag.wl != NULL) {
wp = state->tflag.wp;
if (wl != NULL) {
if (wp != NULL)
window_set_active_pane(wp->window, wp);
session_set_current(s, state->tflag.wl);
session_set_current(s, wl);
cmd_find_from_session(&item->shared->current, s);
}
}

174
cmd.c
View File

@ -448,180 +448,6 @@ usage:
return (NULL);
}
static int
cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
struct cmdq_item *item)
{
int targetflags, error;
struct cmd_find_state *fs = NULL;
if (flag == CMD_NONE ||
flag == CMD_CLIENT ||
flag == CMD_CLIENT_CANFAIL)
return (0);
if (c == 't')
fs = &item->state.tflag;
else if (c == 's')
fs = &item->state.sflag;
if (flag == CMD_SESSION_WITHPANE) {
if (target != NULL && target[strcspn(target, ":.")] != '\0')
flag = CMD_PANE;
else
flag = CMD_SESSION_PREFERUNATTACHED;
}
targetflags = 0;
switch (flag) {
case CMD_SESSION:
case CMD_SESSION_CANFAIL:
case CMD_SESSION_PREFERUNATTACHED:
case CMD_SESSION_WITHPANE:
if (flag == CMD_SESSION_CANFAIL)
targetflags |= CMD_FIND_QUIET;
if (flag == CMD_SESSION_PREFERUNATTACHED)
targetflags |= CMD_FIND_PREFER_UNATTACHED;
break;
case CMD_MOVEW_R:
flag = CMD_WINDOW_INDEX;
/* FALLTHROUGH */
case CMD_WINDOW:
case CMD_WINDOW_CANFAIL:
case CMD_WINDOW_MARKED:
case CMD_WINDOW_INDEX:
if (flag == CMD_WINDOW_CANFAIL)
targetflags |= CMD_FIND_QUIET;
if (flag == CMD_WINDOW_MARKED)
targetflags |= CMD_FIND_DEFAULT_MARKED;
if (flag == CMD_WINDOW_INDEX)
targetflags |= CMD_FIND_WINDOW_INDEX;
break;
case CMD_PANE:
case CMD_PANE_CANFAIL:
case CMD_PANE_MARKED:
if (flag == CMD_PANE_CANFAIL)
targetflags |= CMD_FIND_QUIET;
if (flag == CMD_PANE_MARKED)
targetflags |= CMD_FIND_DEFAULT_MARKED;
break;
default:
fatalx("unknown %cflag %d", c, flag);
}
log_debug("%s: flag %c %d %#x", __func__, c, flag, targetflags);
switch (flag) {
case CMD_NONE:
case CMD_CLIENT:
case CMD_CLIENT_CANFAIL:
return (0);
case CMD_SESSION:
case CMD_SESSION_CANFAIL:
case CMD_SESSION_PREFERUNATTACHED:
case CMD_SESSION_WITHPANE:
error = cmd_find_target(fs, item, target, CMD_FIND_SESSION,
targetflags);
if (error != 0)
goto error;
break;
case CMD_MOVEW_R:
error = cmd_find_target(fs, item, target, CMD_FIND_SESSION,
CMD_FIND_QUIET);
if (error == 0)
break;
/* FALLTHROUGH */
case CMD_WINDOW:
case CMD_WINDOW_CANFAIL:
case CMD_WINDOW_MARKED:
case CMD_WINDOW_INDEX:
error = cmd_find_target(fs, item, target, CMD_FIND_WINDOW,
targetflags);
if (error != 0)
goto error;
break;
case CMD_PANE:
case CMD_PANE_CANFAIL:
case CMD_PANE_MARKED:
error = cmd_find_target(fs, item, target, CMD_FIND_PANE,
targetflags);
if (error != 0)
goto error;
break;
default:
fatalx("unknown %cflag %d", c, flag);
}
return (0);
error:
if (~targetflags & CMD_FIND_QUIET)
return (-1);
cmd_find_clear_state(fs, 0);
return (0);
}
int
cmd_prepare_state(struct cmd *cmd, struct cmdq_item *item)
{
const struct cmd_entry *entry = cmd->entry;
struct cmd_state *state = &item->state;
char *tmp;
enum cmd_entry_flag flag;
const char *s;
int error;
tmp = cmd_print(cmd);
log_debug("preparing state for %s (client %p)", tmp, item->client);
free(tmp);
state->c = NULL;
cmd_find_clear_state(&state->tflag, 0);
cmd_find_clear_state(&state->sflag, 0);
flag = cmd->entry->cflag;
if (flag == CMD_NONE) {
flag = cmd->entry->tflag;
if (flag == CMD_CLIENT || flag == CMD_CLIENT_CANFAIL)
s = args_get(cmd->args, 't');
else
s = NULL;
} else
s = args_get(cmd->args, 'c');
switch (flag) {
case CMD_CLIENT:
state->c = cmd_find_client(item, s, 0);
if (state->c == NULL)
return (-1);
break;
default:
state->c = cmd_find_client(item, s, 1);
break;
}
log_debug("using client %p", state->c);
s = args_get(cmd->args, 't');
log_debug("preparing -t state: target %s", s == NULL ? "none" : s);
error = cmd_prepare_state_flag('t', s, entry->tflag, item);
if (error != 0)
return (error);
s = args_get(cmd->args, 's');
log_debug("preparing -s state: target %s", s == NULL ? "none" : s);
error = cmd_prepare_state_flag('s', s, entry->sflag, item);
if (error != 0)
return (error);
if (!cmd_find_empty_state(&state->tflag) &&
!cmd_find_valid_state(&state->tflag))
fatalx("invalid -t state");
if (!cmd_find_empty_state(&state->sflag) &&
!cmd_find_valid_state(&state->sflag))
fatalx("invalid -s state");
return (0);
}
char *
cmd_print(struct cmd *cmd)
{

52
tmux.h
View File

@ -1162,13 +1162,7 @@ struct cmd_find_state {
#define CMD_FIND_DEFAULT_MARKED 0x8
#define CMD_FIND_EXACT_SESSION 0x10
#define CMD_FIND_EXACT_WINDOW 0x20
/* Context for command being executed. */
struct cmd_state {
struct client *c;
struct cmd_find_state tflag;
struct cmd_find_state sflag;
};
#define CMD_FIND_CANFAIL 0x40
/* Command and list of commands. */
struct cmd {
@ -1237,40 +1231,24 @@ struct cmdq_item {
#define CMDQ_NOHOOKS 0x4
struct cmdq_shared *shared;
struct cmd_find_state source;
struct cmd_find_state target;
struct cmd_list *cmdlist;
struct cmd *cmd;
cmdq_cb cb;
void *data;
struct cmd_state state;
TAILQ_ENTRY(cmdq_item) entry;
};
TAILQ_HEAD(cmdq_list, cmdq_item);
/* Command -c, -t or -s flags. */
enum cmd_entry_flag {
CMD_NONE,
CMD_CLIENT,
CMD_CLIENT_CANFAIL,
CMD_SESSION,
CMD_SESSION_CANFAIL,
CMD_SESSION_PREFERUNATTACHED,
CMD_SESSION_WITHPANE, /* implies PREFERUNATTACHED */
CMD_WINDOW,
CMD_WINDOW_CANFAIL,
CMD_WINDOW_MARKED,
CMD_WINDOW_INDEX,
CMD_PANE,
CMD_PANE_CANFAIL,
CMD_PANE_MARKED,
CMD_MOVEW_R,
/* Command definition flag. */
struct cmd_entry_flag {
char flag;
enum cmd_find_type type;
int flags;
};
/* Command definition. */
@ -1285,16 +1263,15 @@ struct cmd_entry {
} args;
const char *usage;
enum cmd_entry_flag tflag;
enum cmd_entry_flag sflag;
enum cmd_entry_flag cflag;
struct cmd_entry_flag source;
struct cmd_entry_flag target;
#define CMD_STARTSERVER 0x1
#define CMD_READONLY 0x2
#define CMD_AFTERHOOK 0x4
int flags;
enum cmd_retval (*exec)(struct cmd *, struct cmdq_item *);
enum cmd_retval (*exec)(struct cmd *, struct cmdq_item *);
};
/* Client connection. */
@ -1761,7 +1738,6 @@ char **cmd_copy_argv(int, char **);
void cmd_free_argv(int, char **);
char *cmd_stringify_argv(int, char **);
struct cmd *cmd_parse(int, char **, const char *, u_int, char **);
int cmd_prepare_state(struct cmd *, struct cmdq_item *);
char *cmd_print(struct cmd *);
int cmd_mouse_at(struct window_pane *, struct mouse_event *,
u_int *, u_int *, int);
@ -1772,8 +1748,8 @@ char *cmd_template_replace(const char *, const char *, int);
extern const struct cmd_entry *cmd_table[];
/* cmd-attach-session.c */
enum cmd_retval cmd_attach_session(struct cmdq_item *, int, int, const char *,
int);
enum cmd_retval cmd_attach_session(struct cmdq_item *, const char *, int, int,
const char *, int);
/* cmd-list.c */
struct cmd_list *cmd_list_parse(int, char **, const char *, u_int, char **);