summaryrefslogtreecommitdiffstats
path: root/cmd-new-window.c
diff options
context:
space:
mode:
authornicm <nicm>2018-03-01 12:53:08 +0000
committernicm <nicm>2018-03-01 12:53:08 +0000
commit182357f24bc7e16d7d7c85cab0c61974f18df2e7 (patch)
treeaaf97a0274f043e226f216c83f5dfd25db518e98 /cmd-new-window.c
parent508e2f0b3aaf2db9b692863738e7ca75765fc70c (diff)
Expand formats in window and session names.
Diffstat (limited to 'cmd-new-window.c')
-rw-r--r--cmd-new-window.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/cmd-new-window.c b/cmd-new-window.c
index 4baf8f0c..4c9878ed 100644
--- a/cmd-new-window.c
+++ b/cmd-new-window.c
@@ -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;
- char **argv, *cause, *cp, *to_free = NULL;
+ const char *cmd, *path, *template, *tmp;
+ char **argv, *cause, *cp, *cwd, *name;
int argc, detached;
struct environ_entry *envent;
struct cmd_find_state fs;
@@ -93,14 +93,17 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
if (envent != NULL)
path = envent->value;
- if (args_has(args, 'c')) {
- cwd = args_get(args, 'c');
- 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;
+ if ((tmp = args_get(args, 'c')) != NULL)
+ cwd = format_single(item, tmp, c, s, NULL, NULL);
+ else if (item->client != NULL && item->client->session == NULL)
+ cwd = xstrdup(item->client->cwd);
else
- cwd = s->cwd;
+ cwd = xstrdup(s->cwd);
+
+ if ((tmp = args_get(args, 'n')) != NULL)
+ name = format_single(item, tmp, c, s, NULL, NULL);
+ else
+ name = NULL;
wl = NULL;
if (idx != -1)
@@ -124,7 +127,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
if (idx == -1)
idx = -1 - options_get_number(s->options, "base-index");
- wl = session_new(s, args_get(args, 'n'), argc, argv, path, cwd, idx,
+ wl = session_new(s, name, argc, argv, path, cwd, idx,
&cause);
if (wl == NULL) {
cmdq_error(item, "create window failed: %s", cause);
@@ -149,10 +152,12 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
cmd_find_from_winlink(&fs, wl, 0);
hooks_insert(s->hooks, item, &fs, "after-new-window");
- free(to_free);
+ free(name);
+ free(cwd);
return (CMD_RETURN_NORMAL);
error:
- free(to_free);
+ free(name);
+ free(cwd);
return (CMD_RETURN_ERROR);
}