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):
314314 Session (server = self , ** s ) for s in attached_sessions
315315 ] or None
316316
317- def has_session (self , target_session ):
317+ def has_session (self , target_session , exact = True ):
318318 """Return True if session exists. ``$ tmux has-session``.
319319
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
321326 :raises: :exc:`exc.BadSessionName`
322327 :rtype: bool
323328
324329 """
325-
326330 session_check_name (target_session )
327331
332+ if exact :
333+ target_session = '={}' .format (target_session )
334+
328335 proc = self .cmd ('has-session' , '-t%s' % target_session )
329336
330337 if not proc .stdout :
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ def test_has_session(server, session):
1717 """Server.has_session returns True if has session_name exists."""
1818 TEST_SESSION_NAME = session .get ('session_name' )
1919 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 )
2022 assert not server .has_session ('asdf2314324321' )
2123
2224
You can’t perform that action at this time.
0 commit comments