Add -c for respawn-pane and respawn-window, from J Raynor.

This commit is contained in:
nicm 2017-07-21 09:17:19 +00:00
parent 932f6cfbfc
commit 11e2af6df7
6 changed files with 49 additions and 38 deletions

View File

@ -74,8 +74,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
struct termios tio, *tiop; struct termios tio, *tiop;
struct session_group *sg; struct session_group *sg;
const char *newname, *errstr, *template, *group, *prefix; const char *newname, *errstr, *template, *group, *prefix;
const char *path, *cmd, *cwd, *to_free = NULL; const char *path, *cmd, *cwd;
char **argv, *cause, *cp; char **argv, *cause, *cp, *to_free = NULL;
int detached, already_attached, idx, argc; int detached, already_attached, idx, argc;
int is_control = 0; int is_control = 0;
u_int sx, sy; u_int sx, sy;
@ -151,7 +151,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
/* Get the new session working directory. */ /* Get the new session working directory. */
if (args_has(args, 'c')) { if (args_has(args, 'c')) {
cwd = args_get(args, 'c'); cwd = args_get(args, 'c');
to_free = cwd = format_single(item, cwd, c, NULL, NULL, NULL); to_free = format_single(item, cwd, c, NULL, NULL, NULL);
cwd = to_free;
} else if (c != NULL && c->session == NULL && c->cwd != NULL) } else if (c != NULL && c->session == NULL && c->cwd != NULL)
cwd = c->cwd; cwd = c->cwd;
else else
@ -327,16 +328,13 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
cmd_find_from_session(&item->shared->current, s); cmd_find_from_session(&item->shared->current, s);
} }
if (to_free != NULL)
free((void *)to_free);
cmd_find_from_session(&fs, s); cmd_find_from_session(&fs, s);
hooks_insert(s->hooks, item, &fs, "after-new-session"); hooks_insert(s->hooks, item, &fs, "after-new-session");
free(to_free);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
error: error:
if (to_free != NULL) free(to_free);
free((void *)to_free);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }

View File

@ -57,8 +57,8 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
struct winlink *wl = item->target.wl; struct winlink *wl = item->target.wl;
struct client *c = cmd_find_client(item, NULL, 1); struct client *c = cmd_find_client(item, NULL, 1);
int idx = item->target.idx; int idx = item->target.idx;
const char *cmd, *path, *template, *cwd, *to_free; const char *cmd, *path, *template, *cwd;
char **argv, *cause, *cp; char **argv, *cause, *cp, *to_free = NULL;
int argc, detached; int argc, detached;
struct environ_entry *envent; struct environ_entry *envent;
struct cmd_find_state fs; struct cmd_find_state fs;
@ -93,10 +93,10 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
if (envent != NULL) if (envent != NULL)
path = envent->value; path = envent->value;
to_free = NULL;
if (args_has(args, 'c')) { if (args_has(args, 'c')) {
cwd = args_get(args, 'c'); cwd = args_get(args, 'c');
to_free = cwd = format_single(item, cwd, c, s, NULL, NULL); to_free = format_single(item, cwd, c, s, NULL, NULL);
cwd = to_free;
} else if (item->client != NULL && item->client->session == NULL) } else if (item->client != NULL && item->client->session == NULL)
cwd = item->client->cwd; cwd = item->client->cwd;
else else
@ -146,16 +146,13 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
free(cp); free(cp);
} }
if (to_free != NULL)
free((void *)to_free);
cmd_find_from_winlink(&fs, wl); cmd_find_from_winlink(&fs, wl);
hooks_insert(s->hooks, item, &fs, "after-new-window"); hooks_insert(s->hooks, item, &fs, "after-new-window");
free(to_free);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
error: error:
if (to_free != NULL) free(to_free);
free((void *)to_free);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }

View File

@ -34,8 +34,9 @@ const struct cmd_entry cmd_respawn_pane_entry = {
.name = "respawn-pane", .name = "respawn-pane",
.alias = "respawnp", .alias = "respawnp",
.args = { "kt:", 0, -1 }, .args = { "c:kt:", 0, -1 },
.usage = "[-k] " CMD_TARGET_PANE_USAGE " [command]", .usage = "[-c start-directory] [-k] " CMD_TARGET_PANE_USAGE
" [command]",
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@ -50,10 +51,11 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
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 = item->target.wp; struct window_pane *wp = item->target.wp;
struct client *c = cmd_find_client(item, NULL, 1);
struct session *s = item->target.s; struct session *s = item->target.s;
struct environ *env; struct environ *env;
const char *path; const char *path = NULL, *cp;
char *cause; char *cause, *cwd = NULL;
u_int idx; u_int idx;
struct environ_entry *envent; struct environ_entry *envent;
@ -69,7 +71,6 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
screen_reinit(&wp->base); screen_reinit(&wp->base);
input_init(wp); input_init(wp);
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
@ -77,15 +78,20 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
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 pane failed: %s", cause); cmdq_error(item, "respawn pane failed: %s", cause);
free(cause); free(cause);
environ_free(env); environ_free(env);
free(cwd);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
environ_free(env); environ_free(env);
free(cwd);
wp->flags |= PANE_REDRAW; wp->flags |= PANE_REDRAW;
server_status_window(w); server_status_window(w);

View File

@ -34,8 +34,9 @@ const struct cmd_entry cmd_respawn_window_entry = {
.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 },
@ -51,9 +52,10 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
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')) {
@ -73,7 +75,6 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
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
@ -81,16 +82,22 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
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);

View File

@ -61,8 +61,8 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
struct window *w = wl->window; struct window *w = wl->window;
struct window_pane *wp = item->target.wp, *new_wp = NULL; struct window_pane *wp = item->target.wp, *new_wp = NULL;
struct environ *env; struct environ *env;
const char *cmd, *path, *shell, *template, *cwd, *to_free; const char *cmd, *path, *shell, *template, *cwd;
char **argv, *cause, *new_cause, *cp; char **argv, *cause, *new_cause, *cp, *to_free = NULL;
u_int hlimit; u_int hlimit;
int argc, size, percentage; int argc, size, percentage;
enum layout_type type; enum layout_type type;
@ -86,10 +86,10 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
argv = args->argv; argv = args->argv;
} }
to_free = NULL;
if (args_has(args, 'c')) { if (args_has(args, 'c')) {
cwd = args_get(args, 'c'); cwd = args_get(args, 'c');
to_free = cwd = format_single(item, cwd, c, s, NULL, NULL); to_free = format_single(item, cwd, c, s, NULL, NULL);
cwd = to_free;
} else if (item->client != NULL && item->client->session == NULL) } else if (item->client != NULL && item->client->session == NULL)
cwd = item->client->cwd; cwd = item->client->cwd;
else else
@ -172,12 +172,10 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
} }
notify_window("window-layout-changed", w); notify_window("window-layout-changed", w);
if (to_free != NULL)
free((void *)to_free);
cmd_find_from_winlink_pane(&fs, wl, new_wp); cmd_find_from_winlink_pane(&fs, wl, new_wp);
hooks_insert(s->hooks, item, &fs, "after-split-window"); hooks_insert(s->hooks, item, &fs, "after-split-window");
free(to_free);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
error: error:
@ -188,7 +186,6 @@ error:
cmdq_error(item, "create pane failed: %s", cause); cmdq_error(item, "create pane failed: %s", cause);
free(cause); free(cause);
if (to_free != NULL) free(to_free);
free((void *)to_free);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }

6
tmux.1
View File

@ -1834,6 +1834,7 @@ and unzoomed (its normal position in the layout).
begins mouse resizing (only valid if bound to a mouse key binding, see begins mouse resizing (only valid if bound to a mouse key binding, see
.Sx MOUSE SUPPORT ) . .Sx MOUSE SUPPORT ) .
.It Xo Ic respawn-pane .It Xo Ic respawn-pane
.Op Fl c Ar start-directory
.Op Fl k .Op Fl k
.Op Fl t Ar target-pane .Op Fl t Ar target-pane
.Op Ar shell-command .Op Ar shell-command
@ -1848,7 +1849,10 @@ is not given, the command used when the pane was created is executed.
The pane must be already inactive, unless The pane must be already inactive, unless
.Fl k .Fl k
is given, in which case any existing command is killed. is given, in which case any existing command is killed.
.Fl c
specifies a new working directory for the pane.
.It Xo Ic respawn-window .It Xo Ic respawn-window
.Op Fl c Ar start-directory
.Op Fl k .Op Fl k
.Op Fl t Ar target-window .Op Fl t Ar target-window
.Op Ar shell-command .Op Ar shell-command
@ -1863,6 +1867,8 @@ is not given, the command used when the window was created is executed.
The window must be already inactive, unless The window must be already inactive, unless
.Fl k .Fl k
is given, in which case any existing command is killed. is given, in which case any existing command is killed.
.Fl c
specifies a new working directory for the window.
.It Xo Ic rotate-window .It Xo Ic rotate-window
.Op Fl DU .Op Fl DU
.Op Fl t Ar target-window .Op Fl t Ar target-window