diff --git a/.travis.yml b/.travis.yml index 9cf89caa6..f693fffe7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ env: - TMUX_VERSION=1.9a matrix: allow_failures: + - python: pypy3.3-5.2-alpha1 - env: TMUX_VERSION=master before_install: - export PIP_USE_MIRRORS=true diff --git a/libtmux/session.py b/libtmux/session.py index 5e141cf8f..ed5aab597 100644 --- a/libtmux/session.py +++ b/libtmux/session.py @@ -11,6 +11,7 @@ import os from . import exc, formats +from ._compat import text_type from .common import EnvironmentMixin, TmuxMappingObject, \ TmuxRelationalObject, session_check_name, handle_option_error from .window import Window @@ -72,8 +73,13 @@ def cmd(self, *args, **kwargs): Renamed from ``.tmux`` to ``.cmd``. """ - if '-t' not in kwargs: - kwargs['-t'] = self.id + # if -t is not set in any arg yet + if not any('-t' in text_type(x) for x in args): + # insert -t immediately after 1st arg, as per tmux format + new_args = [args[0]] + new_args += ['-t', self.id] + new_args += args[1:] + args = new_args return self.server.cmd(*args, **kwargs) def attach_session(self): diff --git a/tests/test_session.py b/tests/test_session.py index 96460d1fa..c1e8dfcfb 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -235,3 +235,12 @@ def test_periods_raise_badsessionname(server, session, session_name, raises): session.rename_session(new_name) with pytest.raises(exc.LibTmuxException): server.switch_client(new_name) + + +def test_cmd_inserts_sesion_id(session): + current_session_id = session.id + last_arg = 'last-arg' + cmd = session.cmd('not-a-command', last_arg) + assert '-t' in cmd.cmd + assert current_session_id in cmd.cmd + assert cmd.cmd[-1] == last_arg