From 96c37fa80a46e189b9b6535242aa1966f4d375c8 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 4 Jan 2011 02:03:41 +0000 Subject: [PATCH] Now that parsing is common, merge some of the small, related commands together to use the same code. Also add some arguments (such as -n and -p) to some commands to match existing commands. --- Makefile | 12 +++--- cmd-last-pane.c | 57 ------------------------- cmd-last-window.c | 57 ------------------------- cmd-lock-client.c | 52 ----------------------- cmd-lock-server.c | 40 ++++++++++++++++-- cmd-lock-session.c | 52 ----------------------- cmd-next-layout.c | 53 ------------------------ cmd-next-window.c | 71 -------------------------------- cmd-previous-layout.c | 53 ------------------------ cmd-previous-window.c | 71 -------------------------------- cmd-select-layout.c | 42 +++++++++++++++++-- cmd-select-pane.c | 27 +++++++++++- cmd-select-window.c | 87 +++++++++++++++++++++++++++++++++++---- cmd-set-option.c | 13 +++++- cmd-set-window-option.c | 46 --------------------- cmd-show-options.c | 13 +++++- cmd-show-window-options.c | 49 ---------------------- tmux.1 | 30 +++++++++++++- 18 files changed, 238 insertions(+), 587 deletions(-) delete mode 100644 cmd-last-pane.c delete mode 100644 cmd-last-window.c delete mode 100644 cmd-lock-client.c delete mode 100644 cmd-lock-session.c delete mode 100644 cmd-next-layout.c delete mode 100644 cmd-next-window.c delete mode 100644 cmd-previous-layout.c delete mode 100644 cmd-previous-window.c delete mode 100644 cmd-set-window-option.c delete mode 100644 cmd-show-window-options.c diff --git a/Makefile b/Makefile index 0f7f403e..4c48ccdb 100644 --- a/Makefile +++ b/Makefile @@ -9,20 +9,20 @@ SRCS= arguments.c attributes.c cfg.c client.c clock.c \ cmd-choose-buffer.c cmd-delete-buffer.c cmd-detach-client.c \ cmd-find-window.c cmd-has-session.c cmd-kill-pane.c \ cmd-kill-server.c cmd-kill-session.c cmd-kill-window.c \ - cmd-last-pane.c cmd-last-window.c cmd-link-window.c cmd-list-buffers.c \ + cmd-link-window.c cmd-list-buffers.c \ cmd-list-clients.c cmd-list-commands.c cmd-list-keys.c \ cmd-list-sessions.c cmd-list-windows.c cmd-list-panes.c \ cmd-list.c cmd-load-buffer.c cmd-join-pane.c \ - cmd-lock-server.c cmd-lock-client.c cmd-lock-session.c \ + cmd-lock-server.c \ cmd-move-window.c cmd-new-session.c cmd-new-window.c \ - cmd-next-layout.c cmd-next-window.c cmd-paste-buffer.c \ - cmd-previous-layout.c cmd-previous-window.c cmd-refresh-client.c \ + cmd-paste-buffer.c \ + cmd-refresh-client.c \ cmd-rename-session.c cmd-rename-window.c cmd-resize-pane.c \ cmd-respawn-window.c cmd-rotate-window.c cmd-save-buffer.c \ cmd-select-layout.c cmd-select-pane.c cmd-select-window.c \ cmd-send-keys.c cmd-send-prefix.c cmd-server-info.c cmd-set-buffer.c \ - cmd-set-option.c cmd-set-window-option.c cmd-show-buffer.c \ - cmd-show-messages.c cmd-show-options.c cmd-show-window-options.c \ + cmd-set-option.c cmd-show-buffer.c \ + cmd-show-messages.c cmd-show-options.c \ cmd-source-file.c cmd-split-window.c cmd-start-server.c cmd-string.c \ cmd-run-shell.c cmd-suspend-client.c cmd-swap-pane.c cmd-swap-window.c \ cmd-switch-client.c cmd-unbind-key.c cmd-unlink-window.c \ diff --git a/cmd-last-pane.c b/cmd-last-pane.c deleted file mode 100644 index f9f61495..00000000 --- a/cmd-last-pane.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2010 Nicholas Marriott - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include "tmux.h" - -/* - * Move to last pane. - */ - -int cmd_last_pane_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_last_pane_entry = { - "last-pane", "lastp", - "t:", 0, 0, - CMD_TARGET_WINDOW_USAGE, - 0, - NULL, - NULL, - cmd_last_pane_exec -}; - -int -cmd_last_pane_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct winlink *wl; - struct window *w; - - if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) - return (-1); - w = wl->window; - - if (w->last == NULL) { - ctx->error(ctx, "no last pane"); - return (-1); - } - window_set_active_pane(w, w->last); - - return (0); -} diff --git a/cmd-last-window.c b/cmd-last-window.c deleted file mode 100644 index 209f367b..00000000 --- a/cmd-last-window.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2007 Nicholas Marriott - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include "tmux.h" - -/* - * Move to last window. - */ - -int cmd_last_window_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_last_window_entry = { - "last-window", "last", - "t:", 0, 0, - CMD_TARGET_SESSION_USAGE, - 0, - NULL, - NULL, - cmd_last_window_exec -}; - -int -cmd_last_window_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct session *s; - - if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL) - return (-1); - - if (session_last(s) == 0) - server_redraw_session(s); - else { - ctx->error(ctx, "no last window"); - return (-1); - } - recalculate_sizes(); - - return (0); -} diff --git a/cmd-lock-client.c b/cmd-lock-client.c deleted file mode 100644 index bc5a1aa4..00000000 --- a/cmd-lock-client.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2009 Nicholas Marriott - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include "tmux.h" - -/* - * Lock a single client. - */ - -int cmd_lock_client_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_lock_client_entry = { - "lock-client", "lockc", - "t:", 0, 0, - CMD_TARGET_CLIENT_USAGE, - 0, - NULL, - NULL, - cmd_lock_client_exec -}; - -int -cmd_lock_client_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct client *c; - - if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) - return (-1); - - server_lock_client(c); - recalculate_sizes(); - - return (0); -} diff --git a/cmd-lock-server.c b/cmd-lock-server.c index 347cc128..955de11f 100644 --- a/cmd-lock-server.c +++ b/cmd-lock-server.c @@ -25,7 +25,7 @@ #include "tmux.h" /* - * Lock server. + * Lock commands. */ int cmd_lock_server_exec(struct cmd *, struct cmd_ctx *); @@ -40,11 +40,45 @@ const struct cmd_entry cmd_lock_server_entry = { cmd_lock_server_exec }; +const struct cmd_entry cmd_lock_session_entry = { + "lock-session", "locks", + "t:", 0, 0, + CMD_TARGET_SESSION_USAGE, + 0, + NULL, + NULL, + cmd_lock_server_exec +}; + +const struct cmd_entry cmd_lock_client_entry = { + "lock-client", "lockc", + "t:", 0, 0, + CMD_TARGET_CLIENT_USAGE, + 0, + NULL, + NULL, + cmd_lock_server_exec +}; + /* ARGSUSED */ int -cmd_lock_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx) +cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx) { - server_lock(); + struct args *args = self->args; + struct client *c; + struct session *s; + + if (self->entry == &cmd_lock_server_entry) + server_lock(); + else if (self->entry == &cmd_lock_session_entry) { + if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL) + return (-1); + server_lock_session(s); + } else { + if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) + return (-1); + server_lock_client(c); + } recalculate_sizes(); return (0); diff --git a/cmd-lock-session.c b/cmd-lock-session.c deleted file mode 100644 index 4b75c973..00000000 --- a/cmd-lock-session.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2009 Nicholas Marriott - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include "tmux.h" - -/* - * Lock all clients attached to a session. - */ - -int cmd_lock_session_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_lock_session_entry = { - "lock-session", "locks", - "t:", 0, 0, - CMD_TARGET_SESSION_USAGE, - 0, - NULL, - NULL, - cmd_lock_session_exec -}; - -int -cmd_lock_session_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct session *s; - - if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL) - return (-1); - - server_lock_session(s); - recalculate_sizes(); - - return (0); -} diff --git a/cmd-next-layout.c b/cmd-next-layout.c deleted file mode 100644 index bdd6f3e5..00000000 --- a/cmd-next-layout.c +++ /dev/null @@ -1,53 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2009 Nicholas Marriott - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include "tmux.h" - -/* - * Switch window to next layout. - */ - -int cmd_next_layout_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_next_layout_entry = { - "next-layout", "nextl", - "t:", 0, 0, - CMD_TARGET_WINDOW_USAGE, - 0, - NULL, - NULL, - cmd_next_layout_exec -}; - -int -cmd_next_layout_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct winlink *wl; - u_int layout; - - if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) - return (-1); - - layout = layout_set_next(wl->window); - ctx->info(ctx, "arranging in: %s", layout_set_name(layout)); - - return (0); -} diff --git a/cmd-next-window.c b/cmd-next-window.c deleted file mode 100644 index c9cb77a9..00000000 --- a/cmd-next-window.c +++ /dev/null @@ -1,71 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2007 Nicholas Marriott - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include "tmux.h" - -/* - * Move to next window. - */ - -void cmd_next_window_key_binding(struct cmd *, int); -int cmd_next_window_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_next_window_entry = { - "next-window", "next", - "at:", 0, 0, - "[-a] " CMD_TARGET_SESSION_USAGE, - 0, - cmd_next_window_key_binding, - NULL, - cmd_next_window_exec -}; - -void -cmd_next_window_key_binding(struct cmd *self, int key) -{ - self->args = args_create(0); - if (key == ('n' | KEYC_ESCAPE)) - args_set(self->args, 'a', NULL); -} - -int -cmd_next_window_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct session *s; - int activity; - - if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL) - return (-1); - - activity = 0; - if (args_has(self->args, 'a')) - activity = 1; - - if (session_next(s, activity) == 0) - server_redraw_session(s); - else { - ctx->error(ctx, "no next window"); - return (-1); - } - recalculate_sizes(); - - return (0); -} diff --git a/cmd-previous-layout.c b/cmd-previous-layout.c deleted file mode 100644 index abe9e357..00000000 --- a/cmd-previous-layout.c +++ /dev/null @@ -1,53 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2009 Nicholas Marriott - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include "tmux.h" - -/* - * Switch window to previous layout. - */ - -int cmd_previous_layout_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_previous_layout_entry = { - "previous-layout", "prevl", - "t:", 0, 0, - CMD_TARGET_WINDOW_USAGE, - 0, - NULL, - NULL, - cmd_previous_layout_exec -}; - -int -cmd_previous_layout_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct winlink *wl; - u_int layout; - - if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) - return (-1); - - layout = layout_set_previous(wl->window); - ctx->info(ctx, "arranging in: %s", layout_set_name(layout)); - - return (0); -} diff --git a/cmd-previous-window.c b/cmd-previous-window.c deleted file mode 100644 index c3f60a29..00000000 --- a/cmd-previous-window.c +++ /dev/null @@ -1,71 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2007 Nicholas Marriott - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include "tmux.h" - -/* - * Move to previous window. - */ - -void cmd_previous_window_key_binding(struct cmd *, int); -int cmd_previous_window_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_previous_window_entry = { - "previous-window", "prev", - "at:", 0, 0, - "[-a] " CMD_TARGET_SESSION_USAGE, - 0, - cmd_previous_window_key_binding, - NULL, - cmd_previous_window_exec -}; - -void -cmd_previous_window_key_binding(struct cmd *self, int key) -{ - self->args = args_create(0); - if (key == ('p' | KEYC_ESCAPE)) - args_set(self->args, 'a', NULL); -} - -int -cmd_previous_window_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct session *s; - int activity; - - if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL) - return (-1); - - activity = 0; - if (args_has(self->args, 'a')) - activity = 1; - - if (session_previous(s, activity) == 0) - server_redraw_session(s); - else { - ctx->error(ctx, "no previous window"); - return (-1); - } - recalculate_sizes(); - - return (0); -} diff --git a/cmd-select-layout.c b/cmd-select-layout.c index df977b0f..b030c311 100644 --- a/cmd-select-layout.c +++ b/cmd-select-layout.c @@ -29,14 +29,34 @@ int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_select_layout_entry = { "select-layout", "selectl", - "t:", 0, 1, - CMD_TARGET_WINDOW_USAGE " [layout-name]", + "npt:", 0, 1, + "[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]", 0, cmd_select_layout_key_binding, NULL, cmd_select_layout_exec }; +const struct cmd_entry cmd_next_layout_entry = { + "next-layout", "nextl", + "t:", 0, 0, + CMD_TARGET_WINDOW_USAGE, + 0, + NULL, + NULL, + cmd_select_layout_exec +}; + +const struct cmd_entry cmd_previous_layout_entry = { + "previous-layout", "prevl", + "t:", 0, 0, + CMD_TARGET_WINDOW_USAGE, + 0, + NULL, + NULL, + cmd_select_layout_exec +}; + void cmd_select_layout_key_binding(struct cmd *self, int key) { @@ -68,11 +88,27 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx) struct args *args = self->args; struct winlink *wl; const char *layoutname; - int layout; + int next, previous, layout; if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) return (-1); + next = self->entry == &cmd_next_layout_entry; + if (args_has(self->args, 'n')) + next = 1; + previous = self->entry == &cmd_previous_layout_entry; + if (args_has(self->args, 'p')) + previous = 1; + + if (next || previous) { + if (next) + layout = layout_set_next(wl->window); + else + layout = layout_set_previous(wl->window); + ctx->info(ctx, "arranging in: %s", layout_set_name(layout)); + return (0); + } + if (args->argc == 0) layout = wl->window->lastlayout; else diff --git a/cmd-select-pane.c b/cmd-select-pane.c index a250bb6e..9aed0a92 100644 --- a/cmd-select-pane.c +++ b/cmd-select-pane.c @@ -29,14 +29,24 @@ int cmd_select_pane_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_select_pane_entry = { "select-pane", "selectp", - "DLRt:U", 0, 0, - "[-DLRU] " CMD_TARGET_PANE_USAGE, + "lDLRt:U", 0, 0, + "[-lDLRU] " CMD_TARGET_PANE_USAGE, 0, cmd_select_pane_key_binding, NULL, cmd_select_pane_exec }; +const struct cmd_entry cmd_last_pane_entry = { + "last-pane", "lastp", + "t:", 0, 0, + CMD_TARGET_WINDOW_USAGE, + 0, + NULL, + NULL, + cmd_select_pane_exec +}; + void cmd_select_pane_key_binding(struct cmd *self, int key) { @@ -60,6 +70,19 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx) struct winlink *wl; struct window_pane *wp; + if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) { + wl = cmd_find_window(ctx, args_get(args, 't'), NULL); + if (wl == NULL) + return (-1); + + if (wl->window->last == NULL) { + ctx->error(ctx, "no last pane"); + return (-1); + } + window_set_active_pane(wl->window, wl->window->last); + return (0); + } + if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL) return (-1); diff --git a/cmd-select-window.c b/cmd-select-window.c index c414af3a..0e1b9543 100644 --- a/cmd-select-window.c +++ b/cmd-select-window.c @@ -31,23 +31,56 @@ int cmd_select_window_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_select_window_entry = { "select-window", "selectw", - "t:", 0, 0, - CMD_TARGET_WINDOW_USAGE, + "lnpt:", 0, 0, + "[-lnp] " CMD_TARGET_WINDOW_USAGE, 0, cmd_select_window_key_binding, NULL, cmd_select_window_exec }; +const struct cmd_entry cmd_next_window_entry = { + "next-window", "next", + "at:", 0, 0, + "[-a] " CMD_TARGET_SESSION_USAGE, + 0, + cmd_select_window_key_binding, + NULL, + cmd_select_window_exec +}; + +const struct cmd_entry cmd_previous_window_entry = { + "previous-window", "prev", + "at:", 0, 0, + "[-a] " CMD_TARGET_SESSION_USAGE, + 0, + cmd_select_window_key_binding, + NULL, + cmd_select_window_exec +}; + +const struct cmd_entry cmd_last_window_entry = { + "last-window", "last", + "t:", 0, 0, + CMD_TARGET_SESSION_USAGE, + 0, + NULL, + NULL, + cmd_select_window_exec +}; + void cmd_select_window_key_binding(struct cmd *self, int key) { char tmp[16]; - xsnprintf(tmp, sizeof tmp, ":%d", key - '0'); - self->args = args_create(0); - args_set(self->args, 't', tmp); + if (key >= '0' && key <= '9') { + xsnprintf(tmp, sizeof tmp, ":%d", key - '0'); + args_set(self->args, 't', tmp); + } + if (key == ('n' | KEYC_ESCAPE) || key == ('p' | KEYC_ESCAPE)) + args_set(self->args, 'a', NULL); } int @@ -56,12 +89,50 @@ cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx) struct args *args = self->args; struct winlink *wl; struct session *s; + int next, previous, last, activity; - if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL) - return (-1); + next = self->entry == &cmd_next_window_entry; + if (args_has(self->args, 'n')) + next = 1; + previous = self->entry == &cmd_previous_window_entry; + if (args_has(self->args, 'p')) + previous = 1; + last = self->entry == &cmd_last_window_entry; + if (args_has(self->args, 'l')) + last = 1; + + if (next || previous || last) { + s = cmd_find_session(ctx, args_get(args, 't')); + if (s == NULL) + return (-1); + + activity = args_has(self->args, 'a'); + if (next) { + if (session_next(s, activity) != 0) { + ctx->error(ctx, "no next window"); + return (-1); + } + } else if (previous) { + if (session_previous(s, activity) != 0) { + ctx->error(ctx, "no previous window"); + return (-1); + } + } else { + if (session_last(s) != 0) { + ctx->error(ctx, "no last window"); + return (-1); + } + } - if (session_select(s, wl->idx) == 0) server_redraw_session(s); + } else { + wl = cmd_find_window(ctx, args_get(args, 't'), &s); + if (wl == NULL) + return (-1); + + if (session_select(s, wl->idx) == 0) + server_redraw_session(s); + } recalculate_sizes(); return (0); diff --git a/cmd-set-option.c b/cmd-set-option.c index efd5797a..436e529e 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -68,6 +68,16 @@ const struct cmd_entry cmd_set_option_entry = { cmd_set_option_exec }; +const struct cmd_entry cmd_set_window_option_entry = { + "set-window-option", "setw", + "agt:u", 1, 2, + "[-agu] " CMD_TARGET_WINDOW_USAGE " option [value]", + 0, + NULL, + NULL, + cmd_set_option_exec +}; + int cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) { @@ -87,7 +97,8 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(self->args, 's')) { oo = &global_options; table = server_options_table; - } else if (args_has(self->args, 'w')) { + } else if (args_has(self->args, 'w') || + self->entry == &cmd_set_window_option_entry) { table = window_options_table; if (args_has(self->args, 'g')) oo = &global_w_options; diff --git a/cmd-set-window-option.c b/cmd-set-window-option.c deleted file mode 100644 index 3a750476..00000000 --- a/cmd-set-window-option.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2008 Nicholas Marriott - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include "tmux.h" - -/* - * Set a window option. This is just an alias for set-option -w. - */ - -int cmd_set_window_option_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_set_window_option_entry = { - "set-window-option", "setw", - "agt:u", 1, 2, - "[-agu] " CMD_TARGET_WINDOW_USAGE " option [value]", - 0, - NULL, - NULL, - cmd_set_window_option_exec -}; - -int -cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - - args_set(args, 'w', NULL); - return (cmd_set_option_entry.exec(self, ctx)); -} diff --git a/cmd-show-options.c b/cmd-show-options.c index a36bebdf..cc11ed64 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -39,6 +39,16 @@ const struct cmd_entry cmd_show_options_entry = { cmd_show_options_exec }; +const struct cmd_entry cmd_show_window_options_entry = { + "show-window-options", "showw", + "gt:", 0, 0, + "[-g] " CMD_TARGET_WINDOW_USAGE, + 0, + NULL, + NULL, + cmd_show_options_exec +}; + int cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) { @@ -53,7 +63,8 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(self->args, 's')) { oo = &global_options; table = server_options_table; - } else if (args_has(self->args, 'w')) { + } else if (args_has(self->args, 'w') || + self->entry == &cmd_show_window_options_entry) { table = window_options_table; if (args_has(self->args, 'g')) oo = &global_w_options; diff --git a/cmd-show-window-options.c b/cmd-show-window-options.c deleted file mode 100644 index 4412499a..00000000 --- a/cmd-show-window-options.c +++ /dev/null @@ -1,49 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2008 Nicholas Marriott - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include -#include - -#include "tmux.h" - -/* - * Show window options. This is an alias for show-options -w. - */ - -int cmd_show_window_options_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_show_window_options_entry = { - "show-window-options", "showw", - "gt:", 0, 0, - "[-g] " CMD_TARGET_WINDOW_USAGE, - 0, - NULL, - NULL, - cmd_show_window_options_exec -}; - -int -cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - - args_set(args, 'w', NULL); - return (cmd_show_options_entry.exec(self, ctx)); -} diff --git a/tmux.1 b/tmux.1 index 0f86e195..64ca5ed3 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1255,6 +1255,7 @@ lower) with .Fl U or downward (numerically higher). .It Xo Ic select-layout +.Op Fl np .Op Fl t Ar target-window .Op Ar layout-name .Xc @@ -1263,8 +1264,16 @@ Choose a specific layout for a window. If .Ar layout-name is not given, the last preset layout used (if any) is reapplied. +.Fl n +and +.Fl p +are equivalent to the +.Ic next-layout +and +.Ic previous-layout +commands. .It Xo Ic select-pane -.Op Fl DLRU +.Op Fl lDLRU .Op Fl t Ar target-pane .Xc .D1 (alias: Ic selectp ) @@ -1280,10 +1289,27 @@ or .Fl U is used, respectively the pane below, to the left, to the right, or above the target pane is used. -.It Ic select-window Op Fl t Ar target-window +.Fl l +is the same as using the +.Ic last-pane +command. +.It Xo Ic select-window +.Op Fl lnp +.Op Fl t Ar target-window +.Xc .D1 (alias: Ic selectw ) Select the window at .Ar target-window . +.Fl l , +.Fl n +and +.Fl p +are equivalent to the +.Ic last-window , +.Ic next-window +and +.Ic previous-window +commands. .It Xo Ic split-window .Op Fl dhvP .Oo Fl l