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.
This commit is contained in:
Nicholas Marriott 2011-01-04 02:03:41 +00:00
parent 55346b0d10
commit 96c37fa80a
18 changed files with 238 additions and 587 deletions

View File

@ -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-choose-buffer.c cmd-delete-buffer.c cmd-detach-client.c \
cmd-find-window.c cmd-has-session.c cmd-kill-pane.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-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-clients.c cmd-list-commands.c cmd-list-keys.c \
cmd-list-sessions.c cmd-list-windows.c cmd-list-panes.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-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-move-window.c cmd-new-session.c cmd-new-window.c \
cmd-next-layout.c cmd-next-window.c cmd-paste-buffer.c \ cmd-paste-buffer.c \
cmd-previous-layout.c cmd-previous-window.c cmd-refresh-client.c \ cmd-refresh-client.c \
cmd-rename-session.c cmd-rename-window.c cmd-resize-pane.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-respawn-window.c cmd-rotate-window.c cmd-save-buffer.c \
cmd-select-layout.c cmd-select-pane.c cmd-select-window.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-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-set-option.c cmd-show-buffer.c \
cmd-show-messages.c cmd-show-options.c cmd-show-window-options.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-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-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 \ cmd-switch-client.c cmd-unbind-key.c cmd-unlink-window.c \

View File

@ -1,57 +0,0 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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 <sys/types.h>
#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);
}

View File

@ -1,57 +0,0 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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 <sys/types.h>
#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);
}

View File

@ -1,52 +0,0 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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 <sys/types.h>
#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);
}

View File

@ -25,7 +25,7 @@
#include "tmux.h" #include "tmux.h"
/* /*
* Lock server. * Lock commands.
*/ */
int cmd_lock_server_exec(struct cmd *, struct cmd_ctx *); 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 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 */ /* ARGSUSED */
int 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(); recalculate_sizes();
return (0); return (0);

View File

@ -1,52 +0,0 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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 <sys/types.h>
#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);
}

View File

@ -1,53 +0,0 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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 <sys/types.h>
#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);
}

View File

@ -1,71 +0,0 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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 <sys/types.h>
#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);
}

View File

@ -1,53 +0,0 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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 <sys/types.h>
#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);
}

View File

@ -1,71 +0,0 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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 <sys/types.h>
#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);
}

View File

@ -29,14 +29,34 @@ int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_select_layout_entry = { const struct cmd_entry cmd_select_layout_entry = {
"select-layout", "selectl", "select-layout", "selectl",
"t:", 0, 1, "npt:", 0, 1,
CMD_TARGET_WINDOW_USAGE " [layout-name]", "[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
0, 0,
cmd_select_layout_key_binding, cmd_select_layout_key_binding,
NULL, NULL,
cmd_select_layout_exec 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 void
cmd_select_layout_key_binding(struct cmd *self, int key) 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 args *args = self->args;
struct winlink *wl; struct winlink *wl;
const char *layoutname; const char *layoutname;
int layout; int next, previous, layout;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
return (-1); 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) if (args->argc == 0)
layout = wl->window->lastlayout; layout = wl->window->lastlayout;
else else

View File

@ -29,14 +29,24 @@ int cmd_select_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_select_pane_entry = { const struct cmd_entry cmd_select_pane_entry = {
"select-pane", "selectp", "select-pane", "selectp",
"DLRt:U", 0, 0, "lDLRt:U", 0, 0,
"[-DLRU] " CMD_TARGET_PANE_USAGE, "[-lDLRU] " CMD_TARGET_PANE_USAGE,
0, 0,
cmd_select_pane_key_binding, cmd_select_pane_key_binding,
NULL, NULL,
cmd_select_pane_exec 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 void
cmd_select_pane_key_binding(struct cmd *self, int key) 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 winlink *wl;
struct window_pane *wp; 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) if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
return (-1); return (-1);

View File

@ -31,23 +31,56 @@ int cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_select_window_entry = { const struct cmd_entry cmd_select_window_entry = {
"select-window", "selectw", "select-window", "selectw",
"t:", 0, 0, "lnpt:", 0, 0,
CMD_TARGET_WINDOW_USAGE, "[-lnp] " CMD_TARGET_WINDOW_USAGE,
0, 0,
cmd_select_window_key_binding, cmd_select_window_key_binding,
NULL, NULL,
cmd_select_window_exec 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 void
cmd_select_window_key_binding(struct cmd *self, int key) cmd_select_window_key_binding(struct cmd *self, int key)
{ {
char tmp[16]; char tmp[16];
xsnprintf(tmp, sizeof tmp, ":%d", key - '0');
self->args = args_create(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 int
@ -56,12 +89,50 @@ cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct args *args = self->args; struct args *args = self->args;
struct winlink *wl; struct winlink *wl;
struct session *s; struct session *s;
int next, previous, last, activity;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL) next = self->entry == &cmd_next_window_entry;
return (-1); 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); 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(); recalculate_sizes();
return (0); return (0);

View File

@ -68,6 +68,16 @@ const struct cmd_entry cmd_set_option_entry = {
cmd_set_option_exec 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 int
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) 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')) { if (args_has(self->args, 's')) {
oo = &global_options; oo = &global_options;
table = server_options_table; 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; table = window_options_table;
if (args_has(self->args, 'g')) if (args_has(self->args, 'g'))
oo = &global_w_options; oo = &global_w_options;

View File

@ -1,46 +0,0 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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 <sys/types.h>
#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));
}

View File

@ -39,6 +39,16 @@ const struct cmd_entry cmd_show_options_entry = {
cmd_show_options_exec 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 int
cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) 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')) { if (args_has(self->args, 's')) {
oo = &global_options; oo = &global_options;
table = server_options_table; 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; table = window_options_table;
if (args_has(self->args, 'g')) if (args_has(self->args, 'g'))
oo = &global_w_options; oo = &global_w_options;

View File

@ -1,49 +0,0 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
*
* 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 <sys/types.h>
#include <stdlib.h>
#include <string.h>
#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));
}

30
tmux.1
View File

@ -1255,6 +1255,7 @@ lower) with
.Fl U .Fl U
or downward (numerically higher). or downward (numerically higher).
.It Xo Ic select-layout .It Xo Ic select-layout
.Op Fl np
.Op Fl t Ar target-window .Op Fl t Ar target-window
.Op Ar layout-name .Op Ar layout-name
.Xc .Xc
@ -1263,8 +1264,16 @@ Choose a specific layout for a window.
If If
.Ar layout-name .Ar layout-name
is not given, the last preset layout used (if any) is reapplied. 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 .It Xo Ic select-pane
.Op Fl DLRU .Op Fl lDLRU
.Op Fl t Ar target-pane .Op Fl t Ar target-pane
.Xc .Xc
.D1 (alias: Ic selectp ) .D1 (alias: Ic selectp )
@ -1280,10 +1289,27 @@ or
.Fl U .Fl U
is used, respectively the pane below, to the left, to the right, or above the is used, respectively the pane below, to the left, to the right, or above the
target pane is used. 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 ) .D1 (alias: Ic selectw )
Select the window at Select the window at
.Ar target-window . .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 .It Xo Ic split-window
.Op Fl dhvP .Op Fl dhvP
.Oo Fl l .Oo Fl l