Skip to content

Commit

Permalink
Show message when restarting shell
Browse files Browse the repository at this point in the history
  • Loading branch information
nviennot committed Nov 6, 2019
1 parent c71307e commit 442143c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
8 changes: 8 additions & 0 deletions options-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
40 changes: 31 additions & 9 deletions session.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 442143c

Please sign in to comment.