@@ -379,13 +379,70 @@ def attach_session(self) -> "Session":
379
379
380
380
return self
381
381
382
- def kill_session (self ) -> None :
383
- """Destroy session."""
384
- proc = self .cmd ("kill-session" , "-t%s" % self .session_id )
382
+ def kill (
383
+ self ,
384
+ all_except : t .Optional [bool ] = None ,
385
+ clear : t .Optional [bool ] = None ,
386
+ ) -> None :
387
+ """Kill :class:`Session`, closes linked windows and detach all clients.
388
+
389
+ ``$ tmux kill-session``.
390
+
391
+ Parameters
392
+ ----------
393
+ all_except : bool, optional
394
+ Kill all sessions in server except this one.
395
+ clear : bool, optional
396
+ Clear alerts (bell, activity, or silence) in all windows.
397
+
398
+ Examples
399
+ --------
400
+ Kill a session:
401
+ >>> session_1 = server.new_session()
402
+
403
+ >>> session_1 in server.sessions
404
+ True
405
+
406
+ >>> session_1.kill()
407
+
408
+ >>> session_1 not in server.sessions
409
+ True
410
+
411
+ Kill all sessions except the current one:
412
+ >>> one_session_to_rule_them_all = server.new_session()
413
+
414
+ >>> other_sessions = server.new_session(
415
+ ... ), server.new_session()
416
+
417
+ >>> all([w in server.sessions for w in other_sessions])
418
+ True
419
+
420
+ >>> one_session_to_rule_them_all.kill(all_except=True)
421
+
422
+ >>> all([w not in server.sessions for w in other_sessions])
423
+ True
424
+
425
+ >>> one_session_to_rule_them_all in server.sessions
426
+ True
427
+ """
428
+ flags : t .Tuple [str , ...] = ()
429
+
430
+ if all_except :
431
+ flags += ("-a" ,)
432
+
433
+ if clear : # Clear alerts (bell, activity, or silence) in all windows
434
+ flags += ("-C" ,)
435
+
436
+ proc = self .cmd (
437
+ "kill-session" ,
438
+ * flags ,
439
+ )
385
440
386
441
if proc .stderr :
387
442
raise exc .LibTmuxException (proc .stderr )
388
443
444
+ return None
445
+
389
446
def switch_client (self ) -> "Session" :
390
447
"""Switch client to session.
391
448
@@ -595,6 +652,25 @@ def name(self) -> t.Optional[str]:
595
652
#
596
653
# Legacy: Redundant stuff we want to remove
597
654
#
655
+ def kill_session (self ) -> None :
656
+ """Destroy session.
657
+
658
+ Notes
659
+ -----
660
+ .. deprecated:: 0.30
661
+
662
+ Deprecated in favor of :meth:`.kill()`.
663
+ """
664
+ warnings .warn (
665
+ "Session.kill_session() is deprecated in favor of Session.kill()" ,
666
+ category = DeprecationWarning ,
667
+ stacklevel = 2 ,
668
+ )
669
+ proc = self .cmd ("kill-session" , "-t%s" % self .session_id )
670
+
671
+ if proc .stderr :
672
+ raise exc .LibTmuxException (proc .stderr )
673
+
598
674
def get (self , key : str , default : t .Optional [t .Any ] = None ) -> t .Any :
599
675
"""Return key-based lookup. Deprecated by attributes.
600
676
0 commit comments