Make confirm-before prompt customizable with -p option like
[tmux-openbsd.git] / cmd-respawn-pane.c
blob5e0d16bce4a4e18bdbd588b411bc7b9d3b5c28de
1 /* $Id$ */
3 /*
4 * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
5 * Copyright (c) 2011 Marcel P. Partap <mpartap@gmx.net>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
16 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
17 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
22 #include <unistd.h>
24 #include "tmux.h"
27 * Respawn a pane (restart the command). Kill existing if -k given.
30 int cmd_respawn_pane_exec(struct cmd *, struct cmd_ctx *);
32 const struct cmd_entry cmd_respawn_pane_entry = {
33 "respawn-pane", "respawnp",
34 "kt:", 0, 1,
35 "[-k] " CMD_TARGET_PANE_USAGE " [command]",
37 NULL,
38 NULL,
39 cmd_respawn_pane_exec
42 int
43 cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
45 struct args *args = self->args;
46 struct winlink *wl;
47 struct window *w;
48 struct window_pane *wp;
49 u_int hlimit;
50 struct session *s;
51 struct environ env;
52 const char *cmd;
53 char *cause;
55 if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
56 return (-1);
57 w = wl->window;
59 if (!args_has(self->args, 'k') && wp->fd != -1) {
60 ctx->error(ctx, "pane still active: %s:%u.%u",
61 s->name, wl->idx, window_pane_index(w, wp));
62 return (-1);
65 environ_init(&env);
66 environ_copy(&global_environ, &env);
67 environ_copy(&s->environ, &env);
68 server_fill_environ(s, &env);
70 window_pane_reset_mode(wp);
71 screen_reinit(&wp->base);
72 input_init(wp);
74 if (args->argc != 0)
75 cmd = args->argv[0];
76 else
77 cmd = NULL;
78 if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
79 ctx->error(ctx, "respawn pane failed: %s", cause);
80 xfree(cause);
81 environ_free(&env);
82 return (-1);
84 wp->flags |= PANE_REDRAW;
85 server_status_window(w);
87 environ_free(&env);
88 return (0);