Skip to content
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

Add session id to Session cmds, when appropriate #65

Merged
merged 4 commits into from Aug 18, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
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
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
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