aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornicm <nicm>2021-01-04 08:43:16 +0000
committernicm <nicm>2021-01-04 08:43:16 +0000
commitbd0fb22f0a206a73ec3f41322571d56d9d7d7c5d (patch)
treea66752a7b2677b92bc4eec51a514b005ce0b9540
parent606bd5f8c6be326ea2e4746de5d5e007fd04eef8 (diff)
downloadrtmux-bd0fb22f0a206a73ec3f41322571d56d9d7d7c5d.tar.gz
rtmux-bd0fb22f0a206a73ec3f41322571d56d9d7d7c5d.tar.bz2
rtmux-bd0fb22f0a206a73ec3f41322571d56d9d7d7c5d.zip
Add a variant of remain-on-exit that only keeps the pane if the program
failed, GitHub issue 2513.
-rw-r--r--options-table.c8
-rw-r--r--server-fn.c16
-rw-r--r--tmux.15
3 files changed, 22 insertions, 7 deletions
diff --git a/options-table.c b/options-table.c
index 34a4c57b..a8276c86 100644
--- a/options-table.c
+++ b/options-table.c
@@ -69,6 +69,9 @@ static const char *options_table_set_clipboard_list[] = {
static const char *options_table_window_size_list[] = {
"largest", "smallest", "manual", "latest", NULL
};
+static const char *options_table_remain_on_exit_list[] = {
+ "off", "on", "failed", NULL
+};
/* Status line format. */
#define OPTIONS_TABLE_STATUS_FORMAT1 \
@@ -949,11 +952,12 @@ const struct options_table_entry options_table[] = {
},
{ .name = "remain-on-exit",
- .type = OPTIONS_TABLE_FLAG,
+ .type = OPTIONS_TABLE_CHOICE,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
+ .choices = options_table_remain_on_exit_list,
.default_num = 0,
.text = "Whether panes should remain ('on') or be automatically "
- "killed ('off') when the program inside exits."
+ "killed ('off' or 'failed') when the program inside exits."
},
{ .name = "synchronize-panes",
diff --git a/server-fn.c b/server-fn.c
index d2465569..d0e06c0f 100644
--- a/server-fn.c
+++ b/server-fn.c
@@ -314,6 +314,7 @@ server_destroy_pane(struct window_pane *wp, int notify)
struct grid_cell gc;
time_t t;
char tim[26];
+ int remain_on_exit;
if (wp->fd != -1) {
bufferevent_free(wp->event);
@@ -322,10 +323,17 @@ server_destroy_pane(struct window_pane *wp, int notify)
wp->fd = -1;
}
- if (options_get_number(wp->options, "remain-on-exit")) {
- if (~wp->flags & PANE_STATUSREADY)
- return;
-
+ remain_on_exit = options_get_number(wp->options, "remain-on-exit");
+ if (remain_on_exit != 0 && (~wp->flags & PANE_STATUSREADY))
+ return;
+ switch (remain_on_exit) {
+ case 0:
+ break;
+ case 2:
+ if (WIFEXITED(wp->status) && WEXITSTATUS(wp->status) == 0)
+ break;
+ /* FALLTHROUGH */
+ case 1:
if (wp->flags & PANE_STATUSDRAWN)
return;
wp->flags |= PANE_STATUSDRAWN;
diff --git a/tmux.1 b/tmux.1
index 1376df95..941305e3 100644
--- a/tmux.1
+++ b/tmux.1
@@ -4181,10 +4181,13 @@ interactive application starts and restores it on exit, so that any output
visible before the application starts reappears unchanged after it exits.
.Pp
.It Xo Ic remain-on-exit
-.Op Ic on | off
+.Op Ic on | off | failed
.Xc
A pane with this flag set is not destroyed when the program running in it
exits.
+If set to
+.Ic failed ,
+then only when the program exit status is not zero.
The pane may be reactivated with the
.Ic respawn-pane
command.