Show message when restarting shell

This commit is contained in:
Nicolas Viennot 2019-11-05 21:18:13 -05:00
parent c71307ed5c
commit 442143cd90
2 changed files with 39 additions and 9 deletions

View File

@ -989,6 +989,14 @@ const struct options_table_entry options_table[] = {
.scope = OPTIONS_TABLE_SERVER,
.default_str = ""
},
{ .name = "tmate-foreground-restart",
.type = OPTIONS_TABLE_NUMBER,
.scope = OPTIONS_TABLE_SERVER,
.minimum = 0,
.maximum = 1,
.default_num = 1
},
#endif
{ .name = NULL }

View File

@ -207,6 +207,36 @@ session_free(__unused int fd, __unused short events, void *arg)
}
}
static void maybe_restart_session(void)
{
int fg_restart = options_get_number(global_options, "tmate-foreground-restart");
if (!fg_restart)
return;
/*
* throttle restarts. This is a blocking sleep. It's
* simpler than using a timer, but fairly harmless
* from a blocking perspective.
*/
usleep(500*1000);
next_session_id = 0;
run_initial_client_cmd();
tmate_info("Shell exited. Shell restarted");
struct session *s;
s = RB_MIN(sessions, &sessions);
if (!s)
return;
struct window_pane *wp;
wp = s->curw->window->active;
window_pane_set_mode(wp, &window_copy_mode);
window_copy_init_for_output(wp);
window_copy_add(wp, "%s", "Shell exited. Shell restarted.");
window_copy_add(wp, "%s", "Note: press the following sequence to disconnect from SSH: <Enter>~.");
}
/* Destroy a session. */
void
session_destroy(struct session *s)
@ -239,15 +269,7 @@ session_destroy(struct session *s)
#ifdef TMATE
if (tmate_foreground && !server_exit) {
tmate_info("Shell exited, restarting");
/*
* throttle restarts. This is a blocking sleep.
* It's simpler than using a timer, but fairly harmless
* from a blocking perspective.
*/
usleep(500*1000);
next_session_id = 0;
run_initial_client_cmd();
maybe_restart_session();
} else {
tmate_info("Session closed");
tmate_write_fin();