66"""
77import logging
88import os
9+ import pathlib
910import shutil
1011import subprocess
1112import typing as t
@@ -55,7 +56,7 @@ class Server(EnvironmentMixin):
5556 Examples
5657 --------
5758 >>> server
58- <libtmux.server. Server object at ...>
59+ Server(socket_name=libtmux_test ...)
5960
6061 >>> server.sessions
6162 [Session($1 ...)]
@@ -99,7 +100,7 @@ class Server(EnvironmentMixin):
99100 def __init__ (
100101 self ,
101102 socket_name : t .Optional [str ] = None ,
102- socket_path : t .Optional [str ] = None ,
103+ socket_path : t .Optional [t . Union [ str , pathlib . Path ] ] = None ,
103104 config_file : t .Optional [str ] = None ,
104105 colors : t .Optional [int ] = None ,
105106 ** kwargs : t .Any ,
@@ -108,11 +109,19 @@ def __init__(
108109 self ._windows : t .List [WindowDict ] = []
109110 self ._panes : t .List [PaneDict ] = []
110111
111- if socket_name :
112+ if socket_path is not None :
113+ self .socket_path = socket_path
114+ elif socket_name is not None :
112115 self .socket_name = socket_name
113116
114- if socket_path :
115- self .socket_path = socket_path
117+ tmux_tmpdir = pathlib .Path (os .getenv ("TMUX_TMPDIR" , "/tmp" ))
118+ socket_name = self .socket_name or "default"
119+ if (
120+ tmux_tmpdir is not None
121+ and self .socket_path is None
122+ and self .socket_name is None
123+ ):
124+ self .socket_path = str (tmux_tmpdir / f"tmux-{ os .geteuid ()} " / socket_name )
116125
117126 if config_file :
118127 self .config_file = config_file
@@ -531,6 +540,26 @@ def panes(self) -> QueryList[Pane]: # type:ignore
531540
532541 return QueryList (panes )
533542
543+ #
544+ # Dunder
545+ #
546+ def __eq__ (self , other : object ) -> bool :
547+ assert isinstance (other , Server )
548+ return (
549+ self .socket_name == other .socket_name
550+ and self .socket_path == other .socket_path
551+ )
552+
553+ def __repr__ (self ) -> str :
554+ if self .socket_name is not None :
555+ return (
556+ f"{ self .__class__ .__name__ } "
557+ f"(socket_name={ getattr (self , 'socket_name' )} )"
558+ )
559+ return (
560+ f"{ self .__class__ .__name__ } " f"(socket_path={ getattr (self , 'socket_path' )} )"
561+ )
562+
534563 #
535564 # Legacy: Redundant stuff we want to remove
536565 #
0 commit comments