diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-01-19 21:27:48 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-01-19 21:27:48 +0000 |
commit | 9c2a180d863ef4ed48ce3fbea8e41e389cbbb63e (patch) | |
tree | 04f65f9f05f7cbe197e64d7cd018111f69ea2673 | |
parent | 0ae35011373ed24ae466fc8c4a959acedc6d6731 (diff) |
Permit !, + and - to be used for window targets to specify last window (!), or
next and previous window by number (+ and -).
Also tidy an if in cmd-new-window.c.
-rw-r--r-- | usr.bin/tmux/cmd-new-window.c | 30 | ||||
-rw-r--r-- | usr.bin/tmux/cmd.c | 66 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 11 |
3 files changed, 80 insertions, 27 deletions
diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c index d5eeab4580e..06f7fe7ccf9 100644 --- a/usr.bin/tmux/cmd-new-window.c +++ b/usr.bin/tmux/cmd-new-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-new-window.c,v 1.11 2009/12/03 22:50:10 nicm Exp $ */ +/* $OpenBSD: cmd-new-window.c,v 1.12 2010/01/19 21:27:47 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -129,21 +129,19 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) wl = NULL; if (idx != -1) wl = winlink_find_by_index(&s->windows, idx); - if (wl != NULL) { - if (data->flag_kill) { - /* - * Can't use session_detach as it will destroy session - * if this makes it empty. - */ - session_alert_cancel(s, wl); - winlink_stack_remove(&s->lastw, wl); - winlink_remove(&s->windows, wl); - - /* Force select/redraw if current. */ - if (wl == s->curw) { - data->flag_detached = 0; - s->curw = NULL; - } + if (wl != NULL && data->flag_kill) { + /* + * Can't use session_detach as it will destroy session if this + * makes it empty. + */ + session_alert_cancel(s, wl); + winlink_stack_remove(&s->lastw, wl); + winlink_remove(&s->windows, wl); + + /* Force select/redraw if current. */ + if (wl == s->curw) { + data->flag_detached = 0; + s->curw = NULL; } } diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c index 954dad66056..37494eb51e5 100644 --- a/usr.bin/tmux/cmd.c +++ b/usr.bin/tmux/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.37 2010/01/07 20:52:18 nicm Exp $ */ +/* $OpenBSD: cmd.c,v 1.38 2010/01/19 21:27:47 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -702,11 +702,19 @@ cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp) /* * Then work out the window. An empty string is the current window, - * otherwise try to look it up in the session. + * otherwise try special cases then to look it up in the session. */ if (*winptr == '\0') wl = s->curw; - else if ((wl = cmd_lookup_window(s, winptr, &ambiguous)) == NULL) + else if (winptr[0] == '!' && winptr[1] == '\0') + wl = TAILQ_FIRST(&s->lastw); + else if (winptr[0] == '+' && winptr[1] == '\0') + wl = winlink_next(s->curw); + else if (winptr[0] == '-' && winptr[1] == '\0') + wl = winlink_previous(s->curw); + else + wl = cmd_lookup_window(s, winptr, &ambiguous); + if (wl == NULL) goto not_found; if (sessptr != NULL) @@ -714,8 +722,20 @@ cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp) return (wl); no_colon: - /* No colon in the string, first try as a window then as a session. */ - if ((wl = cmd_lookup_window(s, arg, &ambiguous)) == NULL) { + /* + * No colon in the string, first try special cases, then as a window + * and lastly as a session. + */ + if (arg[0] == '!' && arg[1] == '\0') { + if ((wl = TAILQ_FIRST(&s->lastw)) == NULL) + goto not_found; + } else if (arg[0] == '+' && arg[1] == '\0') { + if ((wl = winlink_next(s->curw)) == NULL) + goto not_found; + } else if (arg[0] == '-' && arg[1] == '\0') { + if ((wl = winlink_previous(s->curw)) == NULL) + goto not_found; + } else if ((wl = cmd_lookup_window(s, arg, &ambiguous)) == NULL) { if (ambiguous) goto not_found; if ((s = cmd_lookup_session(arg, &ambiguous)) == NULL) @@ -757,6 +777,7 @@ int cmd_find_index(struct cmd_ctx *ctx, const char *arg, struct session **sp) { struct session *s; + struct winlink *wl; const char *winptr; char *sessptr = NULL; int idx, ambiguous = 0; @@ -802,8 +823,20 @@ cmd_find_index(struct cmd_ctx *ctx, const char *arg, struct session **sp) * try to look it up in the session. */ if (*winptr == '\0') - idx = -1; - else if ((idx = cmd_lookup_index(s, winptr, &ambiguous)) == -1) { + idx = -1; + else if (winptr[0] == '!' && winptr[1] == '\0') { + if ((wl = TAILQ_FIRST(&s->lastw)) == NULL) + goto not_found; + idx = wl->idx; + } else if (winptr[0] == '+' && winptr[1] == '\0') { + if (s->curw->idx == INT_MAX) + goto not_found; + idx = s->curw->idx + 1; + } else if (winptr[0] == '-' && winptr[1] == '\0') { + if (s->curw->idx == 0) + goto not_found; + idx = s->curw->idx - 1; + } else if ((idx = cmd_lookup_index(s, winptr, &ambiguous)) == -1) { if (ambiguous) goto not_found; ctx->error(ctx, "invalid index: %s", arg); @@ -815,8 +848,23 @@ cmd_find_index(struct cmd_ctx *ctx, const char *arg, struct session **sp) return (idx); no_colon: - /* No colon in the string, first try as a window then as a session. */ - if ((idx = cmd_lookup_index(s, arg, &ambiguous)) == -1) { + /* + * No colon in the string, first try special cases, then as a window + * and lastly as a session. + */ + if (arg[0] == '!' && arg[1] == '\0') { + if ((wl = TAILQ_FIRST(&s->lastw)) == NULL) + goto not_found; + idx = wl->idx; + } else if (arg[0] == '+' && arg[1] == '\0') { + if (s->curw->idx == INT_MAX) + goto not_found; + idx = s->curw->idx + 1; + } else if (arg[0] == '-' && arg[1] == '\0') { + if (s->curw->idx == 0) + goto not_found; + idx = s->curw->idx - 1; + } else if ((idx = cmd_lookup_index(s, arg, &ambiguous)) == -1) { if (ambiguous) goto not_found; if ((s = cmd_lookup_session(arg, &ambiguous)) == NULL) diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index abce87295f4..64640005fe9 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.139 2010/01/18 19:16:04 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.140 2010/01/19 21:27:47 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 18 2010 $ +.Dd $Mdocdate: January 19 2010 $ .Dt TMUX 1 .Os .Sh NAME @@ -307,6 +307,13 @@ commands) otherwise the current window in .Em session is chosen. +The special character +.Ql \&! +uses the last (previously current) window, or +.Ql + +and +.Ql - +are the next window or the previous window by number. When the argument does not contain a colon, .Nm first attempts to parse it as window; if that fails, an attempt is made to |