@@ -58,6 +58,8 @@ class EnvironmentMixin:
58
58
59
59
_add_option = None
60
60
61
+ cmd : t .Callable [[t .Any , t .Any ], "tmux_cmd" ]
62
+
61
63
def __init__ (self , add_option : Optional [str ] = None ) -> None :
62
64
self ._add_option = add_option
63
65
@@ -174,12 +176,15 @@ def getenv(self, name: str) -> Optional[str]:
174
176
str
175
177
Value of environment variable
176
178
"""
177
- tmux_args = ["show-environment" ]
179
+ tmux_args : t .Tuple [t .Union [str , int ], ...] = tuple ()
180
+
181
+ tmux_args += ("show-environment" ,)
178
182
if self ._add_option :
179
- tmux_args += [self ._add_option ]
180
- tmux_args += [name ]
181
- vars = self .cmd (* tmux_args ).stdout
182
- vars = [tuple (item .split ("=" , 1 )) for item in vars ]
183
+ tmux_args += (self ._add_option ,)
184
+ tmux_args += (name ,)
185
+ cmd = self .cmd (* tmux_args )
186
+ output = cmd .stdout
187
+ vars = [tuple (item .split ("=" , 1 )) for item in output ]
183
188
vars_dict = {}
184
189
for t in vars :
185
190
if len (t ) == 2 :
@@ -262,17 +267,18 @@ def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
262
267
263
268
self .returncode = returncode
264
269
265
- self . stdout = console_to_str (stdout )
266
- self . stdout = self . stdout .split ("\n " )
267
- self . stdout = list (filter (None , self . stdout )) # filter empty values
270
+ stdout_str = console_to_str (stdout )
271
+ stdout_split = stdout_str .split ("\n " )
272
+ stdout_filtered = list (filter (None , stdout_split )) # filter empty values
268
273
269
- self . stderr = console_to_str (stderr )
270
- self . stderr = self . stderr .split ("\n " )
271
- self .stderr = list (filter (None , self . stderr )) # filter empty values
274
+ stderr_str = console_to_str (stderr )
275
+ stderr_split = stderr_str .split ("\n " )
276
+ self .stderr = list (filter (None , stderr_split )) # filter empty values
272
277
273
- if "has-session" in cmd and len (self .stderr ):
274
- if not self .stdout :
275
- self .stdout = self .stderr [0 ]
278
+ if "has-session" in cmd and len (self .stderr ) and not stdout_filtered :
279
+ self .stdout = [self .stderr [0 ]]
280
+ else :
281
+ self .stdout = stdout_filtered
276
282
277
283
logger .debug ("self.stdout for {}: \n {}" .format (" " .join (cmd ), self .stdout ))
278
284
0 commit comments