@@ -370,13 +370,38 @@ def attached_window(self) -> "Window":
370370 if len (self ._windows ) == 0 :
371371 raise exc .NoWindowsExist ()
372372
373- def attach_session (self ) -> "Session" :
374- """Return ``$ tmux attach-session`` aka alias: ``$ tmux attach``."""
375- proc = self .cmd ("attach-session" , "-t%s" % self .session_id )
373+ def attach (
374+ self ,
375+ _exit : t .Optional [bool ] = None ,
376+ _flags : t .Optional [t .List [str ]] = None ,
377+ ) -> "Session" :
378+ """Return ``$ tmux attach-session`` aka alias: ``$ tmux attach``.
379+
380+ Examples
381+ --------
382+ >>> session = server.new_session()
383+
384+ >>> session not in server.attached_sessions
385+ True
386+ """
387+ flags : t .Tuple [str , ...] = ()
388+
389+ if _exit is not None and _exit :
390+ flags += ("-x" ,)
391+
392+ if _flags is not None and isinstance (_flags , list ):
393+ flags += tuple (f'{ "," .join (_flags )} ' )
394+
395+ proc = self .cmd (
396+ "attach-session" ,
397+ * flags ,
398+ )
376399
377400 if proc .stderr :
378401 raise exc .LibTmuxException (proc .stderr )
379402
403+ self .refresh ()
404+
380405 return self
381406
382407 def kill (
@@ -652,6 +677,27 @@ def name(self) -> t.Optional[str]:
652677 #
653678 # Legacy: Redundant stuff we want to remove
654679 #
680+ def attach_session (self ) -> "Session" :
681+ """Return ``$ tmux attach-session`` aka alias: ``$ tmux attach``.
682+
683+ Notes
684+ -----
685+ .. deprecated:: 0.30
686+
687+ Deprecated in favor of :meth:`.attach()`.
688+ """
689+ warnings .warn (
690+ "Session.attach_session() is deprecated in favor of Session.attach()" ,
691+ category = DeprecationWarning ,
692+ stacklevel = 2 ,
693+ )
694+ proc = self .cmd ("attach-session" , "-t%s" % self .session_id )
695+
696+ if proc .stderr :
697+ raise exc .LibTmuxException (proc .stderr )
698+
699+ return self
700+
655701 def kill_session (self ) -> None :
656702 """Destroy session.
657703
0 commit comments