summaryrefslogtreecommitdiffstats
path: root/cmd-respawn-window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2011-01-04 00:42:46 +0000
committerNicholas Marriott <nicm@openbsd.org>2011-01-04 00:42:46 +0000
commit7502cb3adbb26a2f94445a35626e64041d6769f9 (patch)
tree6ae4f33f69dc0a470dbe905b5140216fb19b8f01 /cmd-respawn-window.c
parentac3b78a84178a308536a56ea114b0f6f8ce6fb47 (diff)
Clean up and simplify tmux command argument parsing.
Originally, tmux commands were parsed in the client process into a struct with the command data which was then serialised and sent to the server to be executed. The parsing was later moved into the server (an argv was sent from the client), but the parse step and intermediate struct was kept. This change removes that struct and the separate parse step. Argument parsing and printing is now common to all commands (in arguments.c) with each command left with just an optional check function (to validate the arguments at parse time), the exec function and a function to set up any key bindings (renamed from the old init function). This is overall more simple and consistent. There should be no changes to any commands behaviour or syntax although as this touches every command please watch for any unexpected changes.
Diffstat (limited to 'cmd-respawn-window.c')
-rw-r--r--cmd-respawn-window.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c
index 4c8235e7..30601fe5 100644
--- a/cmd-respawn-window.c
+++ b/cmd-respawn-window.c
@@ -30,31 +30,31 @@ int cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_respawn_window_entry = {
"respawn-window", "respawnw",
+ "kt:", 0, 1,
"[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
- CMD_ARG01, "k",
- cmd_target_init,
- cmd_target_parse,
- cmd_respawn_window_exec,
- cmd_target_free,
- cmd_target_print
+ 0,
+ NULL,
+ NULL,
+ cmd_respawn_window_exec
};
int
cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
- struct cmd_target_data *data = self->data;
+ struct args *args = self->args;
struct winlink *wl;
struct window *w;
struct window_pane *wp;
struct session *s;
struct environ env;
+ const char *cmd;
char *cause;
- if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
+ if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
return (-1);
w = wl->window;
- if (!cmd_check_flag(data->chflags, 'k')) {
+ if (!args_has(self->args, 'k')) {
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp->fd == -1)
continue;
@@ -75,8 +75,11 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
window_destroy_panes(w);
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
window_pane_resize(wp, w->sx, w->sy);
- if (window_pane_spawn(
- wp, data->arg, NULL, NULL, &env, s->tio, &cause) != 0) {
+ if (args->argc != 0)
+ cmd = args->argv[0];
+ else
+ cmd = NULL;
+ if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
ctx->error(ctx, "respawn window failed: %s", cause);
xfree(cause);
environ_free(&env);