Switch to prev tmux from hw-diags & ddrescue-tui

* Only during normal exits, not done for aborts/crashes
This commit is contained in:
2Shirt 2019-06-12 15:37:19 -06:00
parent e30e52e880
commit c50627867e
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
3 changed files with 16 additions and 0 deletions

View file

@ -45,6 +45,7 @@ if __name__ == '__main__':
# Done
print_standard('\nDone.')
pause("Press Enter to exit...")
tmux_switch_client()
exit_script()
except GenericAbort:
abort()
@ -55,6 +56,7 @@ if __name__ == '__main__':
print_error(msg)
abort()
except SystemExit as sys_exit:
tmux_switch_client()
exit_script(sys_exit.code)
except:
major_exception()

View file

@ -141,6 +141,18 @@ def tmux_split_window(
return result.stdout.decode().strip()
def tmux_switch_client(target_session=None):
"""Switch to target tmux session, or previous if none specified."""
cmd = ['tmux', 'switch-client']
if target_session:
cmd.extend(['-t', target_session])
else:
# Switch to previous instead
cmd.append('-p')
run_program(cmd, check=False)
def tmux_update_pane(
pane_id, command=None, working_dir=None,
text=None, watch=None, watch_cmd='cat'):

View file

@ -23,6 +23,7 @@ if __name__ == '__main__':
sleep(1)
pause('Press Enter to exit...')
except SystemExit as sys_exit:
tmux_switch_client()
exit_script(sys_exit.code)
except:
# Cleanup
@ -59,6 +60,7 @@ if __name__ == '__main__':
# Done
tmux_kill_all_panes()
tmux_switch_client()
exit_script()
# vim: sts=2 sw=2 ts=2