Skip to content

Retain spaces in quoted strings in window options #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions libtmux/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import logging
import os
import shlex

from . import exc, formats
from .common import (
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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]))
Expand Down
4 changes: 4 additions & 0 deletions tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down