Skip to content

Commit bd15984

Browse files
authored
fix: Allow empty window name in tmuxp (#444)
#445 will address and additional issue where formats of empty strings are potentially being filtered out as if they held no value. In re: tmux-python/tmuxp#822
2 parents f148a86 + 7fdb3f3 commit bd15984

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

CHANGES

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ $ pip install --user --upgrade --pre libtmux
1212

1313
- _Insert changes/features/fixes for next release here_
1414

15+
### Bug fixes
16+
17+
- `Session.new_window()`: Improve support for `window_name: ''` downstream in tmuxp (#444, credit: @trankchung)
18+
1519
## libtmux 0.15.7 (2022-09-23)
1620

1721
- Move `.coveragerc` -> `pyproject.toml` (#443)

src/libtmux/session.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ def new_window(
250250
window_args += (
251251
'-F"%s"' % formats.FORMAT_SEPARATOR.join(tmux_formats),
252252
) # output
253-
if window_name:
254-
window_args += ("-n%s" % window_name,)
253+
if window_name is not None and isinstance(window_name, str):
254+
window_args += ("-n", window_name)
255255

256256
window_args += (
257257
# empty string for window_index will use the first one available

tests/test_window.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66

77
from libtmux import exc
8-
from libtmux.common import has_gte_version
8+
from libtmux.common import has_gte_version, has_lt_version
99
from libtmux.pane import Pane
1010
from libtmux.server import Server
1111
from libtmux.session import Session
@@ -290,3 +290,23 @@ def test_select_layout_accepts_no_arg(server: Server, session: Session) -> None:
290290

291291
window = session.new_window(window_name="test_window")
292292
window.select_layout()
293+
294+
295+
@pytest.mark.skipif(
296+
has_lt_version("3.2"), reason="needs filter introduced in tmux >= 3.2"
297+
)
298+
def test_empty_window_name(session: Session) -> None:
299+
session.set_option("automatic-rename", "off")
300+
window = session.new_window(window_name="''", attach=True)
301+
302+
assert window == session.attached_window
303+
assert window.get("window_name") == "''"
304+
305+
cmd = session.cmd(
306+
"list-windows",
307+
"-F",
308+
"#{window_name}",
309+
"-f",
310+
"#{==:#{session_name}," + session.name + "}",
311+
)
312+
assert "''" in cmd.stdout

0 commit comments

Comments
 (0)