@@ -108,11 +108,43 @@ def remove_environment(self, name):
108108 proc .stderr = proc .stderr [0 ]
109109 raise ValueError ("tmux set-environment stderr: %s" % proc .stderr )
110110
111- def show_environment (self , name = None ):
112- """Show environment ``$ tmux show-environment -t [session] <name> ``.
111+ def show_environment (self ):
112+ """Show environment ``$ tmux show-environment -t [session]``.
113113
114- Return dict of environment variables for the session or the value of a
115- specific variable if the name is specified.
114+ Return dict of environment variables for the session.
115+
116+ .. versionchanged:: 0.13
117+
118+ Removed per-item lookups. Use :meth:`libtmux.common.EnvironmentMixin.getenv`.
119+
120+ Returns
121+ -------
122+ dict
123+ environmental variables in dict, if no name, or str if name
124+ entered.
125+ """
126+ tmux_args = ["show-environment" ]
127+ if self ._add_option :
128+ tmux_args += [self ._add_option ]
129+ vars = self .cmd (* tmux_args ).stdout
130+ vars = [tuple (item .split ("=" , 1 )) for item in vars ]
131+ vars_dict = {}
132+ for t in vars :
133+ if len (t ) == 2 :
134+ vars_dict [t [0 ]] = t [1 ]
135+ elif len (t ) == 1 :
136+ vars_dict [t [0 ]] = True
137+ else :
138+ raise ValueError ("unexpected variable %s" , t )
139+
140+ return vars_dict
141+
142+ def getenv (self , name ):
143+ """Show environment variable ``$ tmux show-environment -t [session] <name>``.
144+
145+ Return the value of a specific variable if the name is specified.
146+
147+ .. versionadded:: 0.13
116148
117149 Parameters
118150 ----------
@@ -121,15 +153,13 @@ def show_environment(self, name=None):
121153
122154 Returns
123155 -------
124- str or dict
125- environmental variables in dict, if no name, or str if name
126- entered.
156+ str
157+ Value of environment variable
127158 """
128159 tmux_args = ["show-environment" ]
129160 if self ._add_option :
130161 tmux_args += [self ._add_option ]
131- if name :
132- tmux_args += [name ]
162+ tmux_args += [name ]
133163 vars = self .cmd (* tmux_args ).stdout
134164 vars = [tuple (item .split ("=" , 1 )) for item in vars ]
135165 vars_dict = {}
@@ -141,10 +171,7 @@ def show_environment(self, name=None):
141171 else :
142172 raise ValueError ("unexpected variable %s" , t )
143173
144- if name :
145- return vars_dict .get (name )
146-
147- return vars_dict
174+ return vars_dict .get (name )
148175
149176
150177class tmux_cmd :
0 commit comments