Skip to content

Commit

Permalink
Add session id to Session cmds, when appropriate (#65)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
askedrelic authored and tony committed Aug 18, 2017
1 parent d6df234 commit 6811ba4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions libtmux/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6811ba4

Please sign in to comment.