diff --git a/libtmux/window.py b/libtmux/window.py index 60115f55c..bc0673c37 100644 --- a/libtmux/window.py +++ b/libtmux/window.py @@ -9,6 +9,7 @@ import logging import os +import shlex from . import exc, formats from .common import ( @@ -183,7 +184,10 @@ def show_window_options(self, option=None, g=False): *tmux_args ).stdout - cmd = [tuple(item.split(' ')) for item in cmd] + # The shlex.split function splits the args at spaces, while also + # retaining quoted sub-strings. + # shlex.split('this is "a test"') => ['this', 'is', 'a test'] + cmd = [tuple(shlex.split(item)) for item in cmd] window_options = dict(cmd) @@ -225,7 +229,7 @@ def show_window_option(self, option, g=False): if not len(cmd.stdout): return None - option = [item.split(' ') for item in cmd.stdout][0] + option = [shlex.split(item) for item in cmd.stdout][0] if option[1].isdigit(): option = (option[0], int(option[1])) diff --git a/tests/test_window.py b/tests/test_window.py index e9b1ebbef..865331baf 100644 --- a/tests/test_window.py +++ b/tests/test_window.py @@ -178,6 +178,10 @@ def test_set_show_window_options(session): assert window.show_window_options('main-pane-height') == 40 assert window.show_window_options()['main-pane-height'] == 40 + if has_gte_version('2.3'): + window.set_window_option('pane-border-format', ' #P ') + assert window.show_window_options('pane-border-format') == ' #P ' + def test_empty_window_option_returns_None(session): window = session.new_window(window_name='test_window')