version 1.35, 2017/04/25 15:35:10 |
version 1.36, 2017/07/21 09:17:19 |
|
|
.name = "respawn-window", |
.name = "respawn-window", |
.alias = "respawnw", |
.alias = "respawnw", |
|
|
.args = { "kt:", 0, -1 }, |
.args = { "c:kt:", 0, -1 }, |
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE " [command]", |
.usage = "[-c start-directory] [-k] " CMD_TARGET_WINDOW_USAGE |
|
" [command]", |
|
|
.target = { 't', CMD_FIND_WINDOW, 0 }, |
.target = { 't', CMD_FIND_WINDOW, 0 }, |
|
|
|
|
struct winlink *wl = item->target.wl; |
struct winlink *wl = item->target.wl; |
struct window *w = wl->window; |
struct window *w = wl->window; |
struct window_pane *wp; |
struct window_pane *wp; |
|
struct client *c = cmd_find_client(item, NULL, 1); |
struct environ *env; |
struct environ *env; |
const char *path; |
const char *path = NULL, *cp; |
char *cause; |
char *cause, *cwd = NULL; |
struct environ_entry *envent; |
struct environ_entry *envent; |
|
|
if (!args_has(self->args, 'k')) { |
if (!args_has(self->args, 'k')) { |
|
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry); |
TAILQ_INSERT_HEAD(&w->panes, wp, entry); |
window_pane_resize(wp, w->sx, w->sy); |
window_pane_resize(wp, w->sx, w->sy); |
|
|
path = NULL; |
|
if (item->client != NULL && item->client->session == NULL) |
if (item->client != NULL && item->client->session == NULL) |
envent = environ_find(item->client->environ, "PATH"); |
envent = environ_find(item->client->environ, "PATH"); |
else |
else |
|
|
if (envent != NULL) |
if (envent != NULL) |
path = envent->value; |
path = envent->value; |
|
|
|
if ((cp = args_get(args, 'c')) != NULL) |
|
cwd = format_single(item, cp, c, s, NULL, NULL); |
|
|
env = environ_for_session(s, 0); |
env = environ_for_session(s, 0); |
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env, |
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, cwd, env, |
s->tio, &cause) != 0) { |
s->tio, &cause) != 0) { |
cmdq_error(item, "respawn window failed: %s", cause); |
cmdq_error(item, "respawn window failed: %s", cause); |
free(cause); |
free(cause); |
environ_free(env); |
environ_free(env); |
|
free(cwd); |
server_destroy_pane(wp, 0); |
server_destroy_pane(wp, 0); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
environ_free(env); |
environ_free(env); |
|
free(cwd); |
|
|
layout_init(w, wp); |
layout_init(w, wp); |
window_pane_reset_mode(wp); |
window_pane_reset_mode(wp); |
screen_reinit(&wp->base); |
screen_reinit(&wp->base); |