Skip to content

Commit 22f7ea8

Browse files
committed
Add session to all Session cmds, if it is not explicitly set
1 parent 084290b commit 22f7ea8

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

libtmux/session.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ def cmd(self, *args, **kwargs):
7272
Renamed from ``.tmux`` to ``.cmd``.
7373
7474
"""
75-
if '-t' not in kwargs:
76-
kwargs['-t'] = self.id
75+
# if -t is not set in any arg yet
76+
if not any('-t' in unicode(x) for x in args):
77+
# insert -t immediately after 1st arg, as per tmux format
78+
new_args = [args[0]]
79+
new_args += ['-t', self.id]
80+
new_args += args[1:]
81+
args = new_args
7782
return self.server.cmd(*args, **kwargs)
7883

7984
def attach_session(self):

tests/test_session.py

+8
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,11 @@ 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+
def test_cmd_inserts_sesion_id(session):
240+
current_session_id = session.id
241+
last_arg = 'last-arg'
242+
cmd = session.cmd('not-a-command', last_arg)
243+
assert '-t' in cmd.cmd
244+
assert current_session_id in cmd.cmd
245+
assert cmd.cmd[-1] == last_arg

0 commit comments

Comments
 (0)