From c4b0da5513ee4c9692f0980408b0da2ee7e3a553 Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 28 Apr 2019 20:05:50 +0000 Subject: Support multiple occurances of the same argument. Use this for a new flag -e to new-window, split-window, respawn-window, respawn-pane to pass environment variables into the newly created process. From Steffen Christgau in GitHub issue 1697. --- cmd-respawn-pane.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'cmd-respawn-pane.c') diff --git a/cmd-respawn-pane.c b/cmd-respawn-pane.c index 44234315..5e23fa15 100644 --- a/cmd-respawn-pane.c +++ b/cmd-respawn-pane.c @@ -34,9 +34,9 @@ const struct cmd_entry cmd_respawn_pane_entry = { .name = "respawn-pane", .alias = "respawnp", - .args = { "c:kt:", 0, -1 }, - .usage = "[-c start-directory] [-k] " CMD_TARGET_PANE_USAGE - " [command]", + .args = { "c:e:kt:", 0, -1 }, + .usage = "[-k] [-c start-directory] [-e environment] " + CMD_TARGET_PANE_USAGE " [command]", .target = { 't', CMD_FIND_PANE, 0 }, @@ -53,6 +53,8 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) struct winlink *wl = item->target.wl; struct window_pane *wp = item->target.wp; char *cause = NULL; + const char *add; + struct args_value *value; memset(&sc, 0, sizeof sc); sc.item = item; @@ -65,6 +67,13 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) sc.name = NULL; sc.argc = args->argc; sc.argv = args->argv; + sc.environ = environ_create(); + + add = args_first_value(args, 'e', &value); + while (add != NULL) { + environ_put(sc.environ, add); + add = args_next_value(&value); + } sc.idx = -1; sc.cwd = args_get(args, 'c'); @@ -82,5 +91,6 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) wp->flags |= PANE_REDRAW; server_status_window(wp->window); + environ_free(sc.environ); return (CMD_RETURN_NORMAL); } -- cgit v1.2.3