File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -314,17 +314,24 @@ def attached_sessions(self):
314
314
Session (server = self , ** s ) for s in attached_sessions
315
315
] or None
316
316
317
- def has_session (self , target_session ):
317
+ def has_session (self , target_session , exact = True ):
318
318
"""Return True if session exists. ``$ tmux has-session``.
319
319
320
- :param: target_session: str of session name.
320
+ :param target_session: session name
321
+ :type target_session: str
322
+ :param exact: match the session name exactly.
323
+ tmux uses fnmatch by default. Internally prepends ``=`` to the
324
+ session in ``$ tmux has-session``.
325
+ :type exact: bool
321
326
:raises: :exc:`exc.BadSessionName`
322
327
:rtype: bool
323
328
324
329
"""
325
-
326
330
session_check_name (target_session )
327
331
332
+ if exact :
333
+ target_session = '={}' .format (target_session )
334
+
328
335
proc = self .cmd ('has-session' , '-t%s' % target_session )
329
336
330
337
if not proc .stdout :
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ def test_has_session(server, session):
17
17
"""Server.has_session returns True if has session_name exists."""
18
18
TEST_SESSION_NAME = session .get ('session_name' )
19
19
assert server .has_session (TEST_SESSION_NAME )
20
+ assert not server .has_session (TEST_SESSION_NAME [:- 2 ])
21
+ assert server .has_session (TEST_SESSION_NAME [:- 2 ], exact = False )
20
22
assert not server .has_session ('asdf2314324321' )
21
23
22
24
You can’t perform that action at this time.
0 commit comments