diff options
author | 2017-07-21 09:17:19 +0000 | |
---|---|---|
committer | 2017-07-21 09:17:19 +0000 | |
commit | 579ab1e83e50fb56f7976e518f5a43ff44aa49c8 (patch) | |
tree | fd581f60d8b3e16daf7010bc7f53e38235432920 /usr.bin/tmux | |
parent | I'm equally upset as Kurt Mosiejczuk, who found irrelevant 22-year (diff) | |
download | wireguard-openbsd-579ab1e83e50fb56f7976e518f5a43ff44aa49c8.tar.xz wireguard-openbsd-579ab1e83e50fb56f7976e518f5a43ff44aa49c8.zip |
Add -c for respawn-pane and respawn-window, from J Raynor.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/cmd-new-session.c | 16 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-new-window.c | 17 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-respawn-pane.c | 20 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-respawn-window.c | 21 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-split-window.c | 17 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 10 |
6 files changed, 56 insertions, 45 deletions
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c index 44920b9cbeb..41c8553c0c3 100644 --- a/usr.bin/tmux/cmd-new-session.c +++ b/usr.bin/tmux/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-new-session.c,v 1.107 2017/05/28 19:46:55 nicm Exp $ */ +/* $OpenBSD: cmd-new-session.c,v 1.108 2017/07/21 09:17:19 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -74,8 +74,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) struct termios tio, *tiop; struct session_group *sg; const char *newname, *errstr, *template, *group, *prefix; - const char *path, *cmd, *cwd, *to_free = NULL; - char **argv, *cause, *cp; + const char *path, *cmd, *cwd; + char **argv, *cause, *cp, *to_free = NULL; int detached, already_attached, idx, argc; int is_control = 0; 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. */ if (args_has(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) cwd = c->cwd; else @@ -327,16 +328,13 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) cmd_find_from_session(&item->shared->current, s); } - if (to_free != NULL) - free((void *)to_free); - cmd_find_from_session(&fs, s); hooks_insert(s->hooks, item, &fs, "after-new-session"); + free(to_free); return (CMD_RETURN_NORMAL); error: - if (to_free != NULL) - free((void *)to_free); + free(to_free); return (CMD_RETURN_ERROR); } diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c index 4bdab690617..9261599d679 100644 --- a/usr.bin/tmux/cmd-new-window.c +++ b/usr.bin/tmux/cmd-new-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-new-window.c,v 1.70 2017/04/22 10:22:39 nicm Exp $ */ +/* $OpenBSD: cmd-new-window.c,v 1.71 2017/07/21 09:17:19 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -57,8 +57,8 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) struct winlink *wl = item->target.wl; struct client *c = cmd_find_client(item, NULL, 1); int idx = item->target.idx; - const char *cmd, *path, *template, *cwd, *to_free; - char **argv, *cause, *cp; + const char *cmd, *path, *template, *cwd; + char **argv, *cause, *cp, *to_free = NULL; int argc, detached; struct environ_entry *envent; struct cmd_find_state fs; @@ -93,10 +93,10 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) if (envent != NULL) path = envent->value; - to_free = NULL; if (args_has(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) cwd = item->client->cwd; else @@ -146,16 +146,13 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) free(cp); } - if (to_free != NULL) - free((void *)to_free); - cmd_find_from_winlink(&fs, wl); hooks_insert(s->hooks, item, &fs, "after-new-window"); + free(to_free); return (CMD_RETURN_NORMAL); error: - if (to_free != NULL) - free((void *)to_free); + free(to_free); return (CMD_RETURN_ERROR); } diff --git a/usr.bin/tmux/cmd-respawn-pane.c b/usr.bin/tmux/cmd-respawn-pane.c index 276f847b055..7fddf1d9405 100644 --- a/usr.bin/tmux/cmd-respawn-pane.c +++ b/usr.bin/tmux/cmd-respawn-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-respawn-pane.c,v 1.25 2017/04/25 15:35:10 nicm Exp $ */ +/* $OpenBSD: cmd-respawn-pane.c,v 1.26 2017/07/21 09:17:19 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -34,8 +34,9 @@ const struct cmd_entry cmd_respawn_pane_entry = { .name = "respawn-pane", .alias = "respawnp", - .args = { "kt:", 0, -1 }, - .usage = "[-k] " CMD_TARGET_PANE_USAGE " [command]", + .args = { "c:kt:", 0, -1 }, + .usage = "[-c start-directory] [-k] " CMD_TARGET_PANE_USAGE + " [command]", .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 window *w = wl->window; struct window_pane *wp = item->target.wp; + struct client *c = cmd_find_client(item, NULL, 1); struct session *s = item->target.s; struct environ *env; - const char *path; - char *cause; + const char *path = NULL, *cp; + char *cause, *cwd = NULL; u_int idx; struct environ_entry *envent; @@ -69,7 +71,6 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) screen_reinit(&wp->base); input_init(wp); - path = NULL; if (item->client != NULL && item->client->session == NULL) envent = environ_find(item->client->environ, "PATH"); else @@ -77,15 +78,20 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) if (envent != NULL) 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); - 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) { cmdq_error(item, "respawn pane failed: %s", cause); free(cause); environ_free(env); + free(cwd); return (CMD_RETURN_ERROR); } environ_free(env); + free(cwd); wp->flags |= PANE_REDRAW; server_status_window(w); diff --git a/usr.bin/tmux/cmd-respawn-window.c b/usr.bin/tmux/cmd-respawn-window.c index f13214a4c16..73c6261eb03 100644 --- a/usr.bin/tmux/cmd-respawn-window.c +++ b/usr.bin/tmux/cmd-respawn-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-respawn-window.c,v 1.35 2017/04/25 15:35:10 nicm Exp $ */ +/* $OpenBSD: cmd-respawn-window.c,v 1.36 2017/07/21 09:17:19 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -34,8 +34,9 @@ const struct cmd_entry cmd_respawn_window_entry = { .name = "respawn-window", .alias = "respawnw", - .args = { "kt:", 0, -1 }, - .usage = "[-k] " CMD_TARGET_WINDOW_USAGE " [command]", + .args = { "c:kt:", 0, -1 }, + .usage = "[-c start-directory] [-k] " CMD_TARGET_WINDOW_USAGE + " [command]", .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 window *w = wl->window; struct window_pane *wp; + struct client *c = cmd_find_client(item, NULL, 1); struct environ *env; - const char *path; - char *cause; + const char *path = NULL, *cp; + char *cause, *cwd = NULL; struct environ_entry *envent; 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); window_pane_resize(wp, w->sx, w->sy); - path = NULL; if (item->client != NULL && item->client->session == NULL) envent = environ_find(item->client->environ, "PATH"); else @@ -81,16 +82,22 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item) if (envent != NULL) 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); - 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) { cmdq_error(item, "respawn window failed: %s", cause); free(cause); environ_free(env); + free(cwd); server_destroy_pane(wp, 0); return (CMD_RETURN_ERROR); } environ_free(env); + free(cwd); + layout_init(w, wp); window_pane_reset_mode(wp); screen_reinit(&wp->base); diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c index 83490ab0dc6..02f0f6766dd 100644 --- a/usr.bin/tmux/cmd-split-window.c +++ b/usr.bin/tmux/cmd-split-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-split-window.c,v 1.85 2017/05/30 21:44:59 nicm Exp $ */ +/* $OpenBSD: cmd-split-window.c,v 1.86 2017/07/21 09:17:19 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -61,8 +61,8 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) struct window *w = wl->window; struct window_pane *wp = item->target.wp, *new_wp = NULL; struct environ *env; - const char *cmd, *path, *shell, *template, *cwd, *to_free; - char **argv, *cause, *new_cause, *cp; + const char *cmd, *path, *shell, *template, *cwd; + char **argv, *cause, *new_cause, *cp, *to_free = NULL; u_int hlimit; int argc, size, percentage; enum layout_type type; @@ -86,10 +86,10 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) argv = args->argv; } - to_free = NULL; if (args_has(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) cwd = item->client->cwd; else @@ -172,12 +172,10 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) } notify_window("window-layout-changed", w); - if (to_free != NULL) - free((void *)to_free); - cmd_find_from_winlink_pane(&fs, wl, new_wp); hooks_insert(s->hooks, item, &fs, "after-split-window"); + free(to_free); return (CMD_RETURN_NORMAL); error: @@ -188,7 +186,6 @@ error: cmdq_error(item, "create pane failed: %s", cause); free(cause); - if (to_free != NULL) - free((void *)to_free); + free(to_free); return (CMD_RETURN_ERROR); } diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 2bbac3f7564..6b62aef3e90 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.567 2017/07/07 14:39:45 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.568 2017/07/21 09:17:19 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: July 7 2017 $ +.Dd $Mdocdate: July 21 2017 $ .Dt TMUX 1 .Os .Sh NAME @@ -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 .Sx MOUSE SUPPORT ) . .It Xo Ic respawn-pane +.Op Fl c Ar start-directory .Op Fl k .Op Fl t Ar target-pane .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 .Fl k 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 +.Op Fl c Ar start-directory .Op Fl k .Op Fl t Ar target-window .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 .Fl k 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 .Op Fl DU .Op Fl t Ar target-window |