Skip to content

Commit db1fe28

Browse files
committed
Environment setting support.
1 parent 0a8568d commit db1fe28

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

tmuxp/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,13 @@ def expand(sconf, cwd=None, parent=None):
189189
sconf['session_name'] = expandshell(sconf['session_name'])
190190
if 'window_name' in sconf:
191191
sconf['window_name'] = expandshell(sconf['window_name'])
192-
192+
if 'environment' in sconf:
193+
for key in sconf['environment']:
194+
val = sconf['environment'][key]
195+
val = expandshell(val)
196+
if any(val.startswith(a) for a in ['.', './']):
197+
val = os.path.normpath(os.path.join(cwd, val))
198+
sconf['environment'][key] = val
193199
# Any config section, session, window, pane that can contain the
194200
# 'shell_command' value
195201
if 'start_directory' in sconf:

tmuxp/session.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,27 @@ def set_option(self, option, value):
330330
proc.stderr = proc.stderr[0]
331331
raise ValueError('tmux set-option stderr: %s' % proc.stderr)
332332

333+
def set_environment(self, name, value):
334+
"""Set environment ``$ tmux set-environment <name> <value>``.
335+
336+
todo: needs tests
337+
338+
:param name: the environment variable name. such as 'PATH'.
339+
:type option: string
340+
:param value: environment value.
341+
:type value: string
342+
343+
"""
344+
345+
proc = self.cmd(
346+
'set-environment', name, value
347+
)
348+
349+
if proc.stderr:
350+
if isinstance(proc.stderr, list) and len(proc.stderr) == int(1):
351+
proc.stderr = proc.stderr[0]
352+
raise ValueError('tmux set-environment stderr: %s' % proc.stderr)
353+
333354
def show_options(self, option=None, g=False):
334355
"""Return a dict of options for the window.
335356

tmuxp/testsuite/workspacebuilder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def test_focus_pane_index(self):
186186
self.assertNotEqual(w.get('window_name'), 'man')
187187

188188
pane_path = '/usr'
189-
for i in range(10):
189+
for i in range(20):
190190
p = w.attached_pane()
191191
p.server._update_panes()
192192
if p.get('pane_current_path') == pane_path:

tmuxp/workspacebuilder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ def build(self, session=None):
143143
except Exception as e:
144144
self.session.kill_session()
145145
raise(e)
146+
if 'environment' in self.sconf:
147+
for option, value in self.sconf['environment'].items():
148+
self.session.set_environment(option, value)
146149

147150
for w, wconf in self.iter_create_windows(session):
148151
assert(isinstance(w, Window))

0 commit comments

Comments
 (0)