Skip to content

Commit 0657ab2

Browse files
committed
[cli] optimize workspace builder error handling. give option to kill, attach or detach session
1 parent d42aecc commit 0657ab2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CHANGES

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Here you can find the recent changes to tmuxp.
1515
to save in JSON or YAML format.
1616
- [cli] [bug] [b6c2e84] Fix bug where tmuxp load w/ session already loaded would
1717
switch/attach even if no was entered
18+
- [cli] when workspace loader crashes, give option to kill session, attach it or
19+
detach it.
1820

1921
2013-10-28
2022
----------

tmuxp/cli.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,32 @@ def load_workspace(config_file, args):
252252
'session_name'])
253253
except exc.TmuxSessionExists as e:
254254
if prompt_yes_no(e.message + ' Attach?'):
255-
255+
# TODO, do we need os.execl for this?
256256
if 'TMUX' in os.environ:
257-
del os.environ['TMUX']
258257
os.execl(tmux_bin, 'tmux', 'switch-client', '-t',
259258
sconfig['session_name'])
260259
else:
261260
os.execl(tmux_bin, 'tmux', 'attach-session', '-t',
262261
sconfig['session_name'])
263262
return
263+
except Exception as e:
264+
logger.error(e)
265+
choice = prompt_choices(
266+
'Error loading workspace. (k)ill, (a)ttach, (d)etach?',
267+
choices=['k', 'a', 'd'],
268+
default='k'
269+
)
270+
271+
if choice == 'k':
272+
builder.session.kill_session()
273+
print('Session killed.')
274+
elif choice == 'a':
275+
if 'TMUX' in os.environ:
276+
builder.session.switch_session()
277+
else:
278+
builder.session.attach_session()
279+
else:
280+
sys.exit()
264281

265282

266283
def command_load(args):

0 commit comments

Comments
 (0)