@@ -597,16 +597,59 @@ def rename_window(self, new_name: str) -> "Window":
597597
598598 return self
599599
600- def kill_window (self ) -> None :
601- """Kill the current :class:`Window` object. ``$ tmux kill-window``."""
600+ def kill (
601+ self ,
602+ all_except : t .Optional [bool ] = None ,
603+ ) -> None :
604+ """Kill :class:`Window`.
605+
606+ ``$ tmux kill-window``.
607+
608+ Examples
609+ --------
610+ Kill a window:
611+ >>> window_1 = session.new_window()
612+
613+ >>> window_1 in session.windows
614+ True
615+
616+ >>> window_1.kill()
617+
618+ >>> window_1 not in session.windows
619+ True
620+
621+ Kill all windows except the current one:
622+ >>> one_window_to_rule_them_all = session.new_window()
623+
624+ >>> other_windows = session.new_window(
625+ ... ), session.new_window()
626+
627+ >>> all([w in session.windows for w in other_windows])
628+ True
629+
630+ >>> one_window_to_rule_them_all.kill(all_except=True)
631+
632+ >>> all([w not in session.windows for w in other_windows])
633+ True
634+
635+ >>> one_window_to_rule_them_all in session.windows
636+ True
637+ """
638+ flags : t .Tuple [str , ...] = ()
639+
640+ if all_except :
641+ flags += ("-a" ,)
642+
602643 proc = self .cmd (
603644 "kill-window" ,
604- f"-t { self . session_id } : { self . window_index } " ,
645+ * flags ,
605646 )
606647
607648 if proc .stderr :
608649 raise exc .LibTmuxException (proc .stderr )
609650
651+ return None
652+
610653 def move_window (
611654 self ,
612655 destination : str = "" ,
@@ -749,6 +792,28 @@ def width(self) -> t.Optional[str]:
749792 #
750793 # Legacy: Redundant stuff we want to remove
751794 #
795+ def kill_window (self ) -> None :
796+ """Kill the current :class:`Window` object. ``$ tmux kill-window``.
797+
798+ Notes
799+ -----
800+ .. deprecated:: 0.30
801+
802+ Deprecated in favor of :meth:`.kill()`.
803+ """
804+ warnings .warn (
805+ "Window.kill_server() is deprecated in favor of Window.kill()" ,
806+ category = DeprecationWarning ,
807+ stacklevel = 2 ,
808+ )
809+ proc = self .cmd (
810+ "kill-window" ,
811+ f"-t{ self .session_id } :{ self .window_index } " ,
812+ )
813+
814+ if proc .stderr :
815+ raise exc .LibTmuxException (proc .stderr )
816+
752817 def get (self , key : str , default : t .Optional [t .Any ] = None ) -> t .Any :
753818 """Return key-based lookup. Deprecated by attributes.
754819
0 commit comments