Skip to content

Commit 6811ba4

Browse files
askedrelictony
authored andcommitted
Add session id to Session cmds, when appropriate (#65)
* Add session to all Session cmds, if it is not explicitly set * fix flake8 warning * use py3 compat text type * allow failures with pypy3.3-5.2-alpha1
1 parent d6df234 commit 6811ba4

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ env:
2121
- TMUX_VERSION=1.9a
2222
matrix:
2323
allow_failures:
24+
- python: pypy3.3-5.2-alpha1
2425
- env: TMUX_VERSION=master
2526
before_install:
2627
- export PIP_USE_MIRRORS=true

libtmux/session.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212

1313
from . import exc, formats
14+
from ._compat import text_type
1415
from .common import EnvironmentMixin, TmuxMappingObject, \
1516
TmuxRelationalObject, session_check_name, handle_option_error
1617
from .window import Window
@@ -72,8 +73,13 @@ def cmd(self, *args, **kwargs):
7273
Renamed from ``.tmux`` to ``.cmd``.
7374
7475
"""
75-
if '-t' not in kwargs:
76-
kwargs['-t'] = self.id
76+
# if -t is not set in any arg yet
77+
if not any('-t' in text_type(x) for x in args):
78+
# insert -t immediately after 1st arg, as per tmux format
79+
new_args = [args[0]]
80+
new_args += ['-t', self.id]
81+
new_args += args[1:]
82+
args = new_args
7783
return self.server.cmd(*args, **kwargs)
7884

7985
def attach_session(self):

tests/test_session.py

+9
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,12 @@ def test_periods_raise_badsessionname(server, session, session_name, raises):
235235
session.rename_session(new_name)
236236
with pytest.raises(exc.LibTmuxException):
237237
server.switch_client(new_name)
238+
239+
240+
def test_cmd_inserts_sesion_id(session):
241+
current_session_id = session.id
242+
last_arg = 'last-arg'
243+
cmd = session.cmd('not-a-command', last_arg)
244+
assert '-t' in cmd.cmd
245+
assert current_session_id in cmd.cmd
246+
assert cmd.cmd[-1] == last_arg

0 commit comments

Comments
 (0)