diff options
author | nicm <nicm> | 2019-04-28 20:05:50 +0000 |
---|---|---|
committer | nicm <nicm> | 2019-04-28 20:05:50 +0000 |
commit | c4b0da5513ee4c9692f0980408b0da2ee7e3a553 (patch) | |
tree | 3bef007901ae51d68f18454f1bbf8a9c2027e11e /cmd-new-window.c | |
parent | dfb7bb683057d08303955c49073f4b475bd0e2d6 (diff) | |
download | rtmux-c4b0da5513ee4c9692f0980408b0da2ee7e3a553.tar.gz rtmux-c4b0da5513ee4c9692f0980408b0da2ee7e3a553.tar.bz2 rtmux-c4b0da5513ee4c9692f0980408b0da2ee7e3a553.zip |
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.
Diffstat (limited to 'cmd-new-window.c')
-rw-r--r-- | cmd-new-window.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/cmd-new-window.c b/cmd-new-window.c index 1007c597..6cb33dd9 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -38,9 +38,9 @@ const struct cmd_entry cmd_new_window_entry = { .name = "new-window", .alias = "neww", - .args = { "ac:dF:kn:Pt:", 0, -1 }, - .usage = "[-adkP] [-c start-directory] [-F format] [-n window-name] " - CMD_TARGET_WINDOW_USAGE " [command]", + .args = { "ac:de:F:kn:Pt:", 0, -1 }, + .usage = "[-adkP] [-c start-directory] [-e environment] [-F format] " + "[-n window-name] " CMD_TARGET_WINDOW_USAGE " [command]", .target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX }, @@ -60,8 +60,9 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) int idx = item->target.idx; struct winlink *new_wl; char *cause = NULL, *cp; - const char *template; + const char *template, *add; struct cmd_find_state fs; + struct args_value *value; if (args_has(args, 'a') && (idx = winlink_shuffle_up(s, wl)) == -1) { cmdq_error(item, "couldn't get a window index"); @@ -75,6 +76,13 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) sc.name = args_get(args, 'n'); 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 = idx; sc.cwd = args_get(args, 'c'); @@ -107,5 +115,6 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) cmd_find_from_winlink(&fs, new_wl, 0); cmdq_insert_hook(s, item, &fs, "after-new-window"); + environ_free(sc.environ); return (CMD_RETURN_NORMAL); } |