The branch, hooks has been updated via 46c21eb3b9818a9cec9fedf76a4446c27ce115a8 (commit) via 378f83e7517fa2fe540b92058d69430ae6b8e185 (commit) via 1d865869101b8ae1ffd1b6b6cf4fac0a262580ec (commit) via 03f4924dbdcb24746b7d7459dec9c686d03d77e3 (commit) via d577796be36b44508dc21c567249fc85b5ace10b (commit) from ad037b7ea361ecbabf7df015e701e12db702978e (commit)
- Log ----------------------------------------------------------------- commit 46c21eb3b9818a9cec9fedf76a4446c27ce115a8 Author: Nicholas Marriott <nicholas.marri...@gmail.com> Commit: Nicholas Marriott <nicholas.marri...@gmail.com> Convert if-shell and run-shell using CMD_PREP_CANFAIL. --- cmd-if-shell.c | 20 ++++---------------- cmd-run-shell.c | 20 ++++---------------- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/cmd-if-shell.c b/cmd-if-shell.c index 1543291..e067b96 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -39,7 +39,7 @@ const struct cmd_entry cmd_if_shell_entry = { "if-shell", "if", "bFt:", 2, 3, "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command [command]", - 0, + CMD_PREP_PANE_T|CMD_PREP_CANFAIL, cmd_if_shell_exec }; @@ -58,23 +58,11 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq) struct cmd_if_shell_data *cdata; char *shellcmd, *cmd, *cause; struct cmd_list *cmdlist; - struct client *c; - struct session *s = NULL; - struct winlink *wl = NULL; - struct window_pane *wp = NULL; + struct session *s = cmdq->state.tflag.s; + struct winlink *wl = cmdq->state.tflag.wl; + struct window_pane *wp = cmdq->state.tflag.wp; struct format_tree *ft; - if (args_has(args, 't')) - wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp); - else { - c = cmd_find_client(cmdq, NULL, 1); - if (c != NULL && c->session != NULL) { - s = c->session; - wl = s->curw; - wp = wl->window->active; - } - } - ft = format_create(); if (s != NULL) format_session(ft, s); diff --git a/cmd-run-shell.c b/cmd-run-shell.c index b47c282..ed1ec1d 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -39,7 +39,7 @@ const struct cmd_entry cmd_run_shell_entry = { "run-shell", "run", "bt:", 1, 1, "[-b] " CMD_TARGET_PANE_USAGE " shell-command", - 0, + CMD_PREP_PANE_T|CMD_PREP_CANFAIL, cmd_run_shell_exec }; @@ -75,23 +75,11 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq) struct args *args = self->args; struct cmd_run_shell_data *cdata; char *shellcmd; - struct client *c; - struct session *s = NULL; - struct winlink *wl = NULL; - struct window_pane *wp = NULL; + struct session *s = cmdq->state.tflag.s; + struct winlink *wl = cmdq->state.tflag.wl; + struct window_pane *wp = cmdq->state.tflag.wp; struct format_tree *ft; - if (args_has(args, 't')) - wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp); - else { - c = cmd_find_client(cmdq, NULL, 1); - if (c != NULL && c->session != NULL) { - s = c->session; - wl = s->curw; - wp = wl->window->active; - } - } - ft = format_create(); if (s != NULL) format_session(ft, s); commit 378f83e7517fa2fe540b92058d69430ae6b8e185 Author: Nicholas Marriott <nicholas.marri...@gmail.com> Commit: Nicholas Marriott <nicholas.marri...@gmail.com> Move all checks for -t into tflag function, and add a CANFAIL flag. --- cmd.c | 151 ++++++++++++++++++++++++++++++++++++++++----------------------- tmux.h | 1 + 2 files changed, 97 insertions(+), 55 deletions(-) diff --git a/cmd.c b/cmd.c index 0cec313..297fca4 100644 --- a/cmd.c +++ b/cmd.c @@ -119,8 +119,8 @@ const struct cmd_entry *cmd_table[] = { void cmd_clear_state(struct cmd_state *); struct client *cmd_get_state_client(struct cmd_q *, int); -int cmd_set_state_tflag(struct cmd *, struct cmd_q *, int); -int cmd_set_state_sflag(struct cmd *, struct cmd_q *, int); +int cmd_set_state_tflag(struct cmd *, struct cmd_q *); +int cmd_set_state_sflag(struct cmd *, struct cmd_q *); int cmd_session_better(struct session *, struct session *, int); struct session *cmd_choose_session_list(struct sessionslist *); struct session *cmd_choose_session(int); @@ -353,16 +353,34 @@ cmd_get_state_client(struct cmd_q *cmdq, int quiet) } int -cmd_set_state_tflag(struct cmd *cmd, struct cmd_q *cmdq, int everything) +cmd_set_state_tflag(struct cmd *cmd, struct cmd_q *cmdq) { struct cmd_state *state = &cmdq->state; - struct args *args = cmd->args; const char *tflag; + int flags = cmd->entry->flags; + int everything = 0; - tflag = args_get(args, 't'); - if (tflag == NULL && !everything) - return (0); + /* + * If the command wants something for -t and no -t argument is present, + * use the base command's -t instead. + */ + tflag = args_get(cmd->args, 't'); + if (tflag == NULL) { + if ((flags & CMD_PREP_ALL_T) == 0) + return (0); /* doesn't care about -t */ + cmd = cmdq->cmd; + everything = 1; + tflag = args_get(cmd->args, 't'); + } + /* + * If no -t and the current command is allowed to fail, just skip to + * fill in as much we can. Otherwise continue and let cmd_find_* fail. + */ + if (tflag == NULL && (flags & CMD_PREP_CANFAIL)) + goto complete_everything; + + /* Fill in state using command (current or base) flags. */ switch (cmd->entry->flags & CMD_PREP_ALL_T) { case 0: break; @@ -390,36 +408,64 @@ cmd_set_state_tflag(struct cmd *cmd, struct cmd_q *cmdq, int everything) default: log_fatalx("too many -t for %s", cmd->entry->name); } - if (everything) { + + /* + * If this is still the current command, it wants what it asked for and + * nothing more. If it's the base command, fill in as much as possible + * because the current command may have different flags. + */ + if (!everything) + return (0); + +complete_everything: + if (state->tflag.s == NULL) { + if (state->c != NULL) + state->tflag.s = state->c->session; + if (state->tflag.s == NULL) + state->tflag.s = cmd_current_session(cmdq, 0); if (state->tflag.s == NULL) { - if (state->c != NULL) - state->tflag.s = state->c->session; - if (state->tflag.s == NULL) - state->tflag.s = cmd_current_session(cmdq, 0); - if (state->tflag.s == NULL) { - cmdq_error(cmdq, "no current session"); - return (-1); - } + if (flags & CMD_PREP_CANFAIL) + return (0); + cmdq_error(cmdq, "no current session"); + return (-1); } - if (state->tflag.wl == NULL) - state->tflag.wl = state->tflag.s->curw; - if (state->tflag.wp == NULL) - state->tflag.wp = state->tflag.wl->window->active; } + if (state->tflag.wl == NULL) + state->tflag.wl = state->tflag.s->curw; + if (state->tflag.wp == NULL) + state->tflag.wp = state->tflag.wl->window->active; return (0); } int -cmd_set_state_sflag(struct cmd *cmd, struct cmd_q *cmdq, int everything) +cmd_set_state_sflag(struct cmd *cmd, struct cmd_q *cmdq) { struct cmd_state *state = &cmdq->state; - struct args *args = cmd->args; const char *sflag; + int flags = cmd->entry->flags; + int everything = 0; - sflag = args_get(args, 's'); - if (sflag == NULL && !everything) - return (0); + /* + * If the command wants something for -s and no -s argument is present, + * use the base command's -s instead. + */ + sflag = args_get(cmd->args, 's'); + if (sflag == NULL) { + if ((flags & CMD_PREP_ALL_S) == 0) + return (0); /* doesn't care about -s */ + cmd = cmdq->cmd; + everything = 1; + sflag = args_get(cmd->args, 's'); + } + + /* + * If no -s and the current command is allowed to fail, just skip to + * fill in as much we can. Otherwise continue and let cmd_find_* fail. + */ + if (sflag == NULL && (flags & CMD_PREP_CANFAIL)) + goto complete_everything; + /* Fill in state using command (current or base) flags. */ switch (cmd->entry->flags & CMD_PREP_ALL_S) { case 0: break; @@ -448,22 +494,31 @@ cmd_set_state_sflag(struct cmd *cmd, struct cmd_q *cmdq, int everything) log_fatalx("too many -s for %s", cmd->entry->name); } - if (everything) { + /* + * If this is still the current command, it wants what it asked for and + * nothing more. If it's the base command, fill in as much as possible + * because the current command may have different flags. + */ + if (!everything) + return (0); + +complete_everything: + if (state->sflag.s == NULL) { + if (state->c != NULL) + state->sflag.s = state->c->session; + if (state->sflag.s == NULL) + state->sflag.s = cmd_current_session(cmdq, 0); if (state->sflag.s == NULL) { - if (state->c != NULL) - state->sflag.s = state->c->session; - if (state->sflag.s == NULL) - state->sflag.s = cmd_current_session(cmdq, 0); - if (state->sflag.s == NULL) { - cmdq_error(cmdq, "no current session"); - return (-1); - } + if (flags & CMD_PREP_CANFAIL) + return (0); + cmdq_error(cmdq, "no current session"); + return (-1); } - if (state->sflag.wl == NULL) - state->sflag.wl = state->sflag.s->curw; - if (state->sflag.wp == NULL) - state->sflag.wp = state->sflag.wl->window->active; } + if (state->sflag.wl == NULL) + state->sflag.wl = state->sflag.s->curw; + if (state->sflag.wp == NULL) + state->sflag.wp = state->sflag.wl->window->active; return (0); } @@ -474,7 +529,6 @@ cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq) struct args *args = cmd->args; const char *cflag; const char *tflag; - const char *sflag; char tmp[BUFSIZ]; int error; @@ -516,22 +570,9 @@ cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq) log_fatalx("both -c and -t for %s", cmd->entry->name); } - /* - * If the command wants something for -t and no -t argument is present, - * use it the base command's -t instead. Same for -s. - */ - tflag = args_get(args, 't'); - if (tflag == NULL && (cmd->entry->flags & CMD_PREP_ALL_T) != 0) - error = cmd_set_state_tflag(cmdq->cmd, cmdq, 1); - else - error = cmd_set_state_tflag(cmd, cmdq, 0); - if (error == 0) { - sflag = args_get(args, 's'); - if (sflag == NULL && (cmd->entry->flags & CMD_PREP_ALL_S) != 0) - error = cmd_set_state_sflag(cmdq->cmd, cmdq, 1); - else - error = cmd_set_state_sflag(cmd, cmdq, 0); - } + error = cmd_set_state_tflag(cmd, cmdq); + if (error == 0) + error = cmd_set_state_sflag(cmd, cmdq); return (error); } diff --git a/tmux.h b/tmux.h index e586ce5..ad1f11f 100644 --- a/tmux.h +++ b/tmux.h @@ -1459,6 +1459,7 @@ struct cmd_entry { #define CMD_PREP_CLIENT_C 0x400 #define CMD_PREP_INDEX_T 0x800 #define CMD_PREP_INDEX_S 0x1000 +#define CMD_PREP_CANFAIL 0x2000 int flags; enum cmd_retval (*exec)(struct cmd *, struct cmd_q *); commit 1d865869101b8ae1ffd1b6b6cf4fac0a262580ec Author: Nicholas Marriott <nicholas.marri...@gmail.com> Commit: Nicholas Marriott <nicholas.marri...@gmail.com> set-option becomes target-window. --- cmd-set-option.c | 2 +- tmux.1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd-set-option.c b/cmd-set-option.c index bda6876..eb80911 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -67,7 +67,7 @@ struct options_entry *cmd_set_option_style(struct cmd *, struct cmd_q *, const struct cmd_entry cmd_set_option_entry = { "set-option", "set", "agoqst:uw", 1, 2, - "[-agosquw] [-t target-session|target-window] option [value]", + "[-agosquw] [-t target-window] option [value]", CMD_PREP_WINDOW_T, cmd_set_option_exec }; diff --git a/tmux.1 b/tmux.1 index a277248..fb394b3 100644 --- a/tmux.1 +++ b/tmux.1 @@ -2073,7 +2073,7 @@ Commands which set options are as follows: .Bl -tag -width Ds .It Xo Ic set-option .Op Fl agoqsuw -.Op Fl t Ar target-session | Ar target-window +.Op Fl t Ar target-window .Ar option Ar value .Xc .D1 (alias: Ic set ) commit 03f4924dbdcb24746b7d7459dec9c686d03d77e3 Author: Nicholas Marriott <nicholas.marri...@gmail.com> Commit: Nicholas Marriott <nicholas.marri...@gmail.com> Use prepare flags for join-pane and move-pane. --- cmd-join-pane.c | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cmd-join-pane.c b/cmd-join-pane.c index 5603541..eddafdc 100644 --- a/cmd-join-pane.c +++ b/cmd-join-pane.c @@ -36,7 +36,7 @@ const struct cmd_entry cmd_join_pane_entry = { "join-pane", "joinp", "bdhvp:l:s:t:", 0, 0, "[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]", - 0, + CMD_PREP_PANE_S|CMD_PREP_PANE_T, cmd_join_pane_exec }; @@ -44,7 +44,7 @@ const struct cmd_entry cmd_move_pane_entry = { "move-pane", "movep", "bdhvp:l:s:t:", 0, 0, "[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]", - 0, + CMD_PREP_PANE_S|CMD_PREP_PANE_T, cmd_join_pane_exec }; @@ -67,16 +67,15 @@ join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window) enum layout_type type; struct layout_cell *lc; - dst_wl = cmd_find_pane(cmdq, args_get(args, 't'), &dst_s, &dst_wp); - if (dst_wl == NULL) - return (CMD_RETURN_ERROR); + dst_s = cmdq->state.tflag.s; + dst_wl = cmdq->state.tflag.wl; + dst_wp = cmdq->state.tflag.wp; dst_w = dst_wl->window; dst_idx = dst_wl->idx; server_unzoom_window(dst_w); - src_wl = cmd_find_pane(cmdq, args_get(args, 's'), NULL, &src_wp); - if (src_wl == NULL) - return (CMD_RETURN_ERROR); + src_wl = cmdq->state.sflag.wl; + src_wp = cmdq->state.sflag.wp; src_w = src_wl->window; server_unzoom_window(src_w); commit d577796be36b44508dc21c567249fc85b5ace10b Author: Nicholas Marriott <nicholas.marri...@gmail.com> Commit: Nicholas Marriott <nicholas.marri...@gmail.com> Use prepare flags for detach-client. --- cmd-detach-client.c | 17 ++++------------- 1 files changed, 4 insertions(+), 13 deletions(-) diff --git a/cmd-detach-client.c b/cmd-detach-client.c index 600554a..174059e 100644 --- a/cmd-detach-client.c +++ b/cmd-detach-client.c @@ -32,7 +32,7 @@ const struct cmd_entry cmd_detach_client_entry = { "detach-client", "detach", "as:t:P", 0, 0, "[-P] [-a] [-s target-session] " CMD_TARGET_CLIENT_USAGE, - CMD_READONLY, + CMD_READONLY|CMD_PREP_CLIENT_T|CMD_PREP_SESSION_S, cmd_detach_client_exec }; @@ -40,7 +40,7 @@ const struct cmd_entry cmd_suspend_client_entry = { "suspend-client", "suspendc", "t:", 0, 0, CMD_TARGET_CLIENT_USAGE, - 0, + CMD_PREP_CLIENT_T, cmd_detach_client_exec }; @@ -48,14 +48,12 @@ enum cmd_retval cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; - struct client *c, *c2; + struct client *c = cmdq->state.c, *c2; struct session *s; enum msgtype msgtype; u_int i; if (self->entry == &cmd_suspend_client_entry) { - if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL) - return (CMD_RETURN_ERROR); tty_stop_tty(&c->tty); c->flags |= CLIENT_SUSPENDED; server_write_client(c, MSG_SUSPEND, NULL, 0); @@ -68,10 +66,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq) msgtype = MSG_DETACH; if (args_has(args, 's')) { - s = cmd_find_session(cmdq, args_get(args, 's'), 0); - if (s == NULL) - return (CMD_RETURN_ERROR); - + s = cmdq->state.sflag.s; for (i = 0; i < ARRAY_LENGTH(&clients); i++) { c = ARRAY_ITEM(&clients, i); if (c == NULL || c->session != s) @@ -80,10 +75,6 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq) strlen(c->session->name) + 1); } } else { - c = cmd_find_client(cmdq, args_get(args, 't'), 0); - if (c == NULL) - return (CMD_RETURN_ERROR); - if (args_has(args, 'a')) { for (i = 0; i < ARRAY_LENGTH(&clients); i++) { c2 = ARRAY_ITEM(&clients, i); ----------------------------------------------------------------------- Summary of changes: cmd-detach-client.c | 17 ++----- cmd-if-shell.c | 20 ++------ cmd-join-pane.c | 15 +++--- cmd-run-shell.c | 20 ++------ cmd-set-option.c | 2 +- cmd.c | 151 ++++++++++++++++++++++++++++++++------------------- tmux.1 | 2 +- tmux.h | 1 + 8 files changed, 118 insertions(+), 110 deletions(-) hooks/post-receive -- tmux ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ tmux-cvs mailing list tmux-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-cvs