diff --git a/CHANGES b/CHANGES index f69037089..74f0a433b 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,10 @@ $ pip install --user --upgrade --pre libtmux - _Insert changes/features/fixes for next release here_ +### Bug fixes + +- `Session.new_window()`: Improve support for `window_name: ''` downstream in tmuxp (#444, credit: @trankchung) + ## libtmux 0.15.7 (2022-09-23) - Move `.coveragerc` -> `pyproject.toml` (#443) diff --git a/src/libtmux/session.py b/src/libtmux/session.py index f996286de..f74c6e2a3 100644 --- a/src/libtmux/session.py +++ b/src/libtmux/session.py @@ -250,8 +250,8 @@ def new_window( window_args += ( '-F"%s"' % formats.FORMAT_SEPARATOR.join(tmux_formats), ) # output - if window_name: - window_args += ("-n%s" % window_name,) + if window_name is not None and isinstance(window_name, str): + window_args += ("-n", window_name) window_args += ( # empty string for window_index will use the first one available diff --git a/tests/test_window.py b/tests/test_window.py index 401716ee5..4c10c9c2a 100644 --- a/tests/test_window.py +++ b/tests/test_window.py @@ -5,7 +5,7 @@ import pytest from libtmux import exc -from libtmux.common import has_gte_version +from libtmux.common import has_gte_version, has_lt_version from libtmux.pane import Pane from libtmux.server import Server from libtmux.session import Session @@ -290,3 +290,23 @@ def test_select_layout_accepts_no_arg(server: Server, session: Session) -> None: window = session.new_window(window_name="test_window") window.select_layout() + + +@pytest.mark.skipif( + has_lt_version("3.2"), reason="needs filter introduced in tmux >= 3.2" +) +def test_empty_window_name(session: Session) -> None: + session.set_option("automatic-rename", "off") + window = session.new_window(window_name="''", attach=True) + + assert window == session.attached_window + assert window.get("window_name") == "''" + + cmd = session.cmd( + "list-windows", + "-F", + "#{window_name}", + "-f", + "#{==:#{session_name}," + session.name + "}", + ) + assert "''" in cmd.stdout