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>
28 * Respawn a pane (restart the command). Kill existing if -k given.
31 enum cmd_retval
cmd_respawn_pane_exec(struct cmd
*, struct cmd_q
*);
33 const struct cmd_entry cmd_respawn_pane_entry
= {
34 "respawn-pane", "respawnp",
36 "[-k] " CMD_TARGET_PANE_USAGE
" [command]",
44 cmd_respawn_pane_exec(struct cmd
*self
, struct cmd_q
*cmdq
)
46 struct args
*args
= self
->args
;
49 struct window_pane
*wp
;
56 if ((wl
= cmd_find_pane(cmdq
, args_get(args
, 't'), &s
, &wp
)) == NULL
)
57 return (CMD_RETURN_ERROR
);
60 if (!args_has(self
->args
, 'k') && wp
->fd
!= -1) {
61 if (window_pane_index(wp
, &idx
) != 0)
62 fatalx("index not found");
63 cmdq_error(cmdq
, "pane still active: %s:%u.%u",
64 s
->name
, wl
->idx
, idx
);
65 return (CMD_RETURN_ERROR
);
69 environ_copy(&global_environ
, &env
);
70 environ_copy(&s
->environ
, &env
);
71 server_fill_environ(s
, &env
);
73 window_pane_reset_mode(wp
);
74 screen_reinit(&wp
->base
);
81 if (window_pane_spawn(wp
, cmd
, NULL
, NULL
, &env
, s
->tio
, &cause
) != 0) {
82 cmdq_error(cmdq
, "respawn pane failed: %s", cause
);
85 return (CMD_RETURN_ERROR
);
87 wp
->flags
|= PANE_REDRAW
;
88 server_status_window(w
);
91 return (CMD_RETURN_NORMAL
);