From 8900f529b2553d9d6b127a579530e4f35c653cb3 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Wed, 26 Apr 2017 17:48:11 -0400 Subject: [PATCH 1/3] Retain spaces in quoted strings in window options Fixes https://github.com/tony/tmuxp/issues/239 With the below in tmux config: setw -g pane-border-format " #P " Before the fix: ('pane-border-format', '"', '#P', '"') After the fix: ('pane-border-format', ' #P ') --- libtmux/window.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libtmux/window.py b/libtmux/window.py index 60115f55c..cfbc7acfa 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) From da6ec0a06e86d4d22a1c63fc6722b8858e002b04 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Thu, 27 Apr 2017 17:14:27 -0500 Subject: [PATCH 2/3] add test for shlex.split on pane-border-format --- tests/test_window.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_window.py b/tests/test_window.py index e9b1ebbef..b967463f5 100644 --- a/tests/test_window.py +++ b/tests/test_window.py @@ -174,6 +174,9 @@ def test_set_show_window_options(session): window.set_window_option('main-pane-height', 20) assert window.show_window_options('main-pane-height') == 20 + window.set_window_option('pane-border-format', ' #P ') + assert window.show_window_options('pane-border-format') == [' #P '] + window.set_window_option('main-pane-height', 40) assert window.show_window_options('main-pane-height') == 40 assert window.show_window_options()['main-pane-height'] == 40 From 6a3a024b1167fec38533f067ecde70e89cbd13b6 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Fri, 28 Apr 2017 13:04:34 -0400 Subject: [PATCH 3/3] Part #2 of shlex.split fix The pane-border-format option was introduced in tmux 2.3, so do not run a test for that on older versions. --- libtmux/window.py | 2 +- tests/test_window.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libtmux/window.py b/libtmux/window.py index cfbc7acfa..bc0673c37 100644 --- a/libtmux/window.py +++ b/libtmux/window.py @@ -229,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 b967463f5..865331baf 100644 --- a/tests/test_window.py +++ b/tests/test_window.py @@ -174,13 +174,14 @@ def test_set_show_window_options(session): window.set_window_option('main-pane-height', 20) assert window.show_window_options('main-pane-height') == 20 - window.set_window_option('pane-border-format', ' #P ') - assert window.show_window_options('pane-border-format') == [' #P '] - window.set_window_option('main-pane-height', 40) 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')