From ff7b5ef005b42abc699850940e35dbf7c1da98a0 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 25 Apr 2017 15:35:10 +0000 Subject: [PATCH] Do not update TERM into config file parsing has finished. --- usr.bin/tmux/cmd-respawn-pane.c | 4 ++-- usr.bin/tmux/cmd-respawn-window.c | 4 ++-- usr.bin/tmux/cmd-split-window.c | 4 ++-- usr.bin/tmux/environ.c | 10 ++++++---- usr.bin/tmux/job.c | 9 +++++++-- usr.bin/tmux/session.c | 4 ++-- usr.bin/tmux/tmux.h | 4 ++-- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/usr.bin/tmux/cmd-respawn-pane.c b/usr.bin/tmux/cmd-respawn-pane.c index 7dac2b9fdf7..276f847b055 100644 --- a/usr.bin/tmux/cmd-respawn-pane.c +++ b/usr.bin/tmux/cmd-respawn-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-respawn-pane.c,v 1.24 2017/04/22 10:22:39 nicm Exp $ */ +/* $OpenBSD: cmd-respawn-pane.c,v 1.25 2017/04/25 15:35:10 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -77,7 +77,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) if (envent != NULL) path = envent->value; - env = environ_for_session(s); + env = environ_for_session(s, 0); if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env, s->tio, &cause) != 0) { cmdq_error(item, "respawn pane failed: %s", cause); diff --git a/usr.bin/tmux/cmd-respawn-window.c b/usr.bin/tmux/cmd-respawn-window.c index d6b3bba55b9..f13214a4c16 100644 --- a/usr.bin/tmux/cmd-respawn-window.c +++ b/usr.bin/tmux/cmd-respawn-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-respawn-window.c,v 1.34 2017/04/22 10:22:39 nicm Exp $ */ +/* $OpenBSD: cmd-respawn-window.c,v 1.35 2017/04/25 15:35:10 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -81,7 +81,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item) if (envent != NULL) path = envent->value; - env = environ_for_session(s); + env = environ_for_session(s, 0); if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env, s->tio, &cause) != 0) { cmdq_error(item, "respawn window failed: %s", cause); diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c index 661fd0959c0..fa42ba43bc9 100644 --- a/usr.bin/tmux/cmd-split-window.c +++ b/usr.bin/tmux/cmd-split-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-split-window.c,v 1.83 2017/04/22 10:22:39 nicm Exp $ */ +/* $OpenBSD: cmd-split-window.c,v 1.84 2017/04/25 15:35:10 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -144,7 +144,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) if (envent != NULL) path = envent->value; - env = environ_for_session(s); + env = environ_for_session(s, 0); if (window_pane_spawn(new_wp, argc, argv, path, shell, cwd, env, s->tio, &cause) != 0) { environ_free(env); diff --git a/usr.bin/tmux/environ.c b/usr.bin/tmux/environ.c index eec2a65f30d..5751ab88a63 100644 --- a/usr.bin/tmux/environ.c +++ b/usr.bin/tmux/environ.c @@ -1,4 +1,4 @@ -/* $OpenBSD: environ.c,v 1.18 2017/03/09 17:02:38 nicm Exp $ */ +/* $OpenBSD: environ.c,v 1.19 2017/04/25 15:35:10 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -222,7 +222,7 @@ environ_log(struct environ *env, const char *prefix) /* Create initial environment for new child. */ struct environ * -environ_for_session(struct session *s) +environ_for_session(struct session *s, int no_TERM) { struct environ *env; const char *value; @@ -233,8 +233,10 @@ environ_for_session(struct session *s) if (s != NULL) environ_copy(s->environ, env); - value = options_get_string(global_options, "default-terminal"); - environ_set(env, "TERM", "%s", value); + if (!no_TERM) { + value = options_get_string(global_options, "default-terminal"); + environ_set(env, "TERM", "%s", value); + } if (s != NULL) idx = s->id; diff --git a/usr.bin/tmux/job.c b/usr.bin/tmux/job.c index 0345fdd1597..74b11f0153f 100644 --- a/usr.bin/tmux/job.c +++ b/usr.bin/tmux/job.c @@ -1,4 +1,4 @@ -/* $OpenBSD: job.c,v 1.43 2017/04/20 09:20:22 nicm Exp $ */ +/* $OpenBSD: job.c,v 1.44 2017/04/25 15:35:10 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -55,7 +55,12 @@ job_run(const char *cmd, struct session *s, const char *cwd, if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0) return (NULL); - env = environ_for_session(s); + /* + * Do not set TERM during .tmux.conf, it is nice to be able to use + * if-shell to decide on default-terminal based on outside TERM. + */ + env = environ_for_session(s, !cfg_finished); + switch (pid = fork()) { case -1: environ_free(env); diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index 64d3a8988d3..ae52de4fdbb 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.73 2017/03/09 17:02:38 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.74 2017/04/25 15:35:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -360,7 +360,7 @@ session_new(struct session *s, const char *name, int argc, char **argv, shell = _PATH_BSHELL; hlimit = options_get_number(s->options, "history-limit"); - env = environ_for_session(s); + env = environ_for_session(s, 0); w = window_create_spawn(name, argc, argv, path, shell, cwd, env, s->tio, s->sx, s->sy, hlimit, cause); if (w == NULL) { diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 3c7903d57f1..ffca8523358 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.751 2017/04/22 10:22:39 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.752 2017/04/25 15:35:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1612,7 +1612,7 @@ void environ_unset(struct environ *, const char *); void environ_update(struct options *, struct environ *, struct environ *); void environ_push(struct environ *); void environ_log(struct environ *, const char *); -struct environ *environ_for_session(struct session *); +struct environ *environ_for_session(struct session *, int); /* tty.c */ void tty_create_log(void); -- 2.20.1