summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Viennot <nicolas@viennot.biz>2019-11-05 21:18:13 -0500
committerNicolas Viennot <nicolas@viennot.biz>2019-11-05 21:39:16 -0500
commit442143cd90bc284b487aa2c723b81c8d33e5e38e (patch)
tree066b118b9fcc7107b3a657ded513c0b3ce47f2c0
parentc71307ed5c9c00c1fdd28add86b5d06a7fceb98e (diff)
Show message when restarting shell
-rw-r--r--options-table.c8
-rw-r--r--session.c40
2 files changed, 39 insertions, 9 deletions
diff --git a/options-table.c b/options-table.c
index dd9f696e..4a20c548 100644
--- a/options-table.c
+++ b/options-table.c
@@ -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 }
diff --git a/session.c b/session.c
index ab58ed9f..d1a644d5 100644
--- a/session.c
+++ b/session.c
@@ -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();