From 4d3ff7cd87e9410d7f093e7f69f7652e48b107b3 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 1 Sep 2023 14:24:46 +0000 Subject: [PATCH] Expand name before looking for window with -S, GitHub issue 3670. --- usr.bin/tmux/cmd-new-window.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c index 599ebd20518..e7dd6e309f8 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.96 2021/08/27 17:25:55 nicm Exp $ */ +/* $OpenBSD: cmd-new-window.c,v 1.97 2023/09/01 14:24:46 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -60,7 +60,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) struct session *s = target->s; struct winlink *wl = target->wl, *new_wl = NULL; int idx = target->idx, before; - char *cause = NULL, *cp; + char *cause = NULL, *cp, *expanded; const char *template, *name; struct cmd_find_state fs; struct args_value *av; @@ -71,16 +71,19 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) */ name = args_get(args, 'n'); if (args_has(args, 'S') && name != NULL && target->idx == -1) { + expanded = format_single(item, name, c, s, NULL, NULL); RB_FOREACH(wl, winlinks, &s->windows) { - if (strcmp(wl->window->name, name) != 0) + if (strcmp(wl->window->name, expanded) != 0) continue; if (new_wl == NULL) { new_wl = wl; continue; } cmdq_error(item, "multiple windows named %s", name); + free(expanded); return (CMD_RETURN_ERROR); } + free(expanded); if (new_wl != NULL) { if (args_has(args, 'd')) return (CMD_RETURN_NORMAL); -- 2.20.1