From ee45a8a149e1a3c8fe7c232a9e32f3a007e21bee Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 22 Apr 2017 10:22:39 +0000 Subject: 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. --- cmd-attach-session.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'cmd-attach-session.c') diff --git a/cmd-attach-session.c b/cmd-attach-session.c index 22d9320d..81ed4a87 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -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'))); } -- cgit