When running multiple sessions and also changing host environment frequently,
it can become troublesome to keep the environment up to date within tmux.

For example if one SSHs in from a different location, the SSH_AUTH_SOCK will
change. This is solved by the update-environment command and can be
conveniently used in a bash alias to go and update the shell of the process
within tmux. E.g.
https://github.com/simonjbeaumont/.dotfiles/blob/master/bash/functions#L66-L78

The only issue is that the environment within tmux is only updated upon
attaching to a session. So the first session to which I "tmux at -t <session>"
to after an SSH will haven its environment updated but no others. If I switch
sessions using the tree choose view, the environment is not updated. The only
way is for me to attach and detach from each session in turn when my host
environment changes.

This patch causes the environment to be updated on switching sessions and
inherits the environment from the session from which you're switching.

I've been running this for a while and it seems to do the right thing.

--
Si
>From 5f27bc3736b68bb2fc67a1f37d371b62ffe0616c Mon Sep 17 00:00:00 2001
From: Si Beaumont <simonjbeaum...@gmail.com>
Date: Thu, 5 Feb 2015 10:28:41 +0000
Subject: [PATCH] Update environment when switching sessions

---
 cmd-switch-client.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/cmd-switch-client.c b/cmd-switch-client.c
index d8f7346..c46cfa2 100644
--- a/cmd-switch-client.c
+++ b/cmd-switch-client.c
@@ -65,7 +65,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
 	struct winlink		*wl = NULL;
 	struct window 		*w = NULL;
 	struct window_pane	*wp = NULL;
-	const char		*tflag;
+	const char		*tflag, *update;
 
 	if ((c = cmd_find_client(cmdq, args_get(args, 'c'), 0)) == NULL)
 		return (CMD_RETURN_ERROR);
@@ -126,6 +126,14 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
 		}
 	}
 
+	/* Update the environment if we're switching clients */
+	if (c != NULL) {
+		if (s != c->session) {
+			update = options_get_string(&global_s_options, "update-environment");
+			environ_update(update, &c->environ, &s->environ);
+		}
+	}
+
 	if (c->session != NULL)
 		c->last_session = c->session;
 	c->session = s;
-- 
1.9.1

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to