@@ -174,7 +174,12 @@ def raise_if_dead(self) -> None:
174174 #
175175 # Command
176176 #
177- def cmd (self , cmd : str , * args : t .Any ) -> tmux_cmd :
177+ def cmd (
178+ self ,
179+ cmd : str ,
180+ * args : t .Any ,
181+ target : t .Optional [t .Union [str , int ]] = None ,
182+ ) -> tmux_cmd :
178183 """Execute tmux command respective of socket name and file, return output.
179184
180185 Examples
@@ -207,6 +212,11 @@ def cmd(self, cmd: str, *args: t.Any) -> tmux_cmd:
207212 ... 'split-window', '-P', '-F#{pane_id}').stdout[0], server=window.server)
208213 Pane(%... Window(@... ...:..., Session($1 libtmux_...)))
209214
215+ Parameters
216+ ----------
217+ target : str, optional
218+ Optional custom target.
219+
210220 Returns
211221 -------
212222 :class:`common.tmux_cmd`
@@ -217,22 +227,25 @@ def cmd(self, cmd: str, *args: t.Any) -> tmux_cmd:
217227
218228 Renamed from ``.tmux`` to ``.cmd``.
219229 """
220- cmd_args : t .List [t .Union [str , int ]] = [cmd , * args ]
230+ svr_args : t .List [t .Union [str , int ]] = [cmd ]
231+ cmd_args : t .List [t .Union [str , int ]] = []
221232 if self .socket_name :
222- cmd_args .insert (0 , f"-L{ self .socket_name } " )
233+ svr_args .insert (0 , f"-L{ self .socket_name } " )
223234 if self .socket_path :
224- cmd_args .insert (0 , f"-S{ self .socket_path } " )
235+ svr_args .insert (0 , f"-S{ self .socket_path } " )
225236 if self .config_file :
226- cmd_args .insert (0 , f"-f{ self .config_file } " )
237+ svr_args .insert (0 , f"-f{ self .config_file } " )
227238 if self .colors :
228239 if self .colors == 256 :
229- cmd_args .insert (0 , "-2" )
240+ svr_args .insert (0 , "-2" )
230241 elif self .colors == 88 :
231- cmd_args .insert (0 , "-8" )
242+ svr_args .insert (0 , "-8" )
232243 else :
233244 raise exc .UnknownColorOption ()
234245
235- return tmux_cmd (* cmd_args )
246+ cmd_args = ["-t" , str (target ), * args ] if target is not None else [* args ]
247+
248+ return tmux_cmd (* svr_args , * cmd_args )
236249
237250 @property
238251 def attached_sessions (self ) -> t .List [Session ]:
@@ -274,7 +287,7 @@ def has_session(self, target_session: str, exact: bool = True) -> bool:
274287 if exact and has_gte_version ("2.1" ):
275288 target_session = f"={ target_session } "
276289
277- proc = self .cmd ("has-session" , "-t%s" % target_session )
290+ proc = self .cmd ("has-session" , target = target_session )
278291
279292 if not proc .returncode :
280293 return True
@@ -318,7 +331,7 @@ def kill_session(self, target_session: t.Union[str, int]) -> "Server":
318331 ------
319332 :exc:`exc.BadSessionName`
320333 """
321- proc = self .cmd ("kill-session" , "-t%s" % target_session )
334+ proc = self .cmd ("kill-session" , target = target_session )
322335
323336 if proc .stderr :
324337 raise exc .LibTmuxException (proc .stderr )
@@ -339,7 +352,7 @@ def switch_client(self, target_session: str) -> None:
339352 """
340353 session_check_name (target_session )
341354
342- proc = self .cmd ("switch-client" , "-t%s" % target_session )
355+ proc = self .cmd ("switch-client" , target = target_session )
343356
344357 if proc .stderr :
345358 raise exc .LibTmuxException (proc .stderr )
@@ -357,12 +370,7 @@ def attach_session(self, target_session: t.Optional[str] = None) -> None:
357370 :exc:`exc.BadSessionName`
358371 """
359372 session_check_name (target_session )
360-
361- tmux_args : t .Tuple [str , ...] = ()
362- if target_session :
363- tmux_args += ("-t%s" % target_session ,)
364-
365- proc = self .cmd ("attach-session" , * tmux_args )
373+ proc = self .cmd ("attach-session" , target = target_session )
366374
367375 if proc .stderr :
368376 raise exc .LibTmuxException (proc .stderr )
@@ -456,7 +464,7 @@ def new_session(
456464
457465 if self .has_session (session_name ):
458466 if kill_session :
459- self .cmd ("kill-session" , "-t%s" % session_name )
467+ self .cmd ("kill-session" , target = session_name )
460468 logger .info ("session %s exists. killed it." % session_name )
461469 else :
462470 raise exc .TmuxSessionExists (
0 commit comments