Skip to content

Commit 935e53f

Browse files
committed
CLI no longer uses OS.execl to switch and attach built sessions
1 parent 19c76be commit 935e53f

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Here you can find the recent changes to tmuxp.
2121
``target-window`` fix.
2222
- [internal] :class:`WorkspaceBuilder` now has ``.session`` attribute accessible
2323
publicly.
24+
- [cli] tmux will now use :meth:`Session.switch_client` and
25+
:meth:`Session.attach_session` to open new sessions instead of ``os.exec``.
2426

2527
2013-10-28
2628
----------

tmuxp/cli.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,22 +243,23 @@ def load_workspace(config_file, args):
243243
builder.build()
244244

245245
if 'TMUX' in os.environ:
246-
if prompt_yes_no('Already inside TMUX, load session?'):
247-
del os.environ['TMUX']
248-
os.execl(tmux_bin, 'tmux', 'switch-client', '-t', sconfig[
249-
'session_name'])
246+
if prompt_yes_no('Already inside TMUX, switch to session?'):
247+
tmux_env = os.environ.pop('TMUX')
248+
builder.session.switch_client()
250249

251-
os.execl(tmux_bin, 'tmux', 'attach-session', '-t', sconfig[
252-
'session_name'])
250+
os.environ['TMUX'] = tmux_env
251+
return
252+
else:
253+
sys.exit('Session created in detached state.')
254+
255+
builder.session.attach_session()
253256
except exc.TmuxSessionExists as e:
254257
if prompt_yes_no(e.message + ' Attach?'):
255-
# TODO, do we need os.execl for this?
256258
if 'TMUX' in os.environ:
257-
os.execl(tmux_bin, 'tmux', 'switch-client', '-t',
258-
sconfig['session_name'])
259+
builder.session.switch_client()
260+
259261
else:
260-
os.execl(tmux_bin, 'tmux', 'attach-session', '-t',
261-
sconfig['session_name'])
262+
builder.session.attach_session()
262263
return
263264
except Exception as e:
264265
logger.error(e)

tmuxp/workspacebuilder.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,19 @@ def build(self, session=None):
112112
)
113113

114114
if self.server.has_session(self.sconf['session_name']):
115+
self.session = self.server.findWhere(
116+
{
117+
'session_name': self.sconf['session_name']
118+
}
119+
)
115120
raise exc.TmuxSessionExists(
116-
'Session name %s is already running.' % self.sconf[
117-
'session_name']
121+
'Session name %s is already running.' %
122+
self.sconf['session_name']
118123
)
119124
else:
120125
session = self.server.new_session(
121-
session_name=self.sconf['session_name'])
126+
session_name=self.sconf['session_name']
127+
)
122128

123129
assert(self.sconf['session_name'] == session.get('session_name'))
124130

0 commit comments

Comments
 (0)