Discussion:
[PATCH] Update environment when switching sessions
(too old to reply)
Si Beaumont
2015-03-31 07:56:15 UTC
Permalink
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
Thomas Adam
2015-04-01 00:24:47 UTC
Permalink
+ /* Update the environment if we're switching clients */
+ if (c != NULL) {
+ if (s != c->session) {
+ update = options_get_string(&global_s_options, "update-environment");
I think you want &s->options here, no?

-- Thomas Adam
--
"Deep in my heart I wish I was wrong. But deep in my heart I know I am
not." -- Morrissey ("Girl Least Likely To" -- off of Viva Hate.)
Si Beaumont
2015-04-01 10:00:43 UTC
Permalink
Post by Thomas Adam
+ update = options_get_string(&global_s_options, "update-environment");
I think you want &s->options here, no?
Ah, yes! Sorry I think I cribbed from the wrong place and what you say is what
happens in the attach command.

Attached is a revised version of the patch.

Si
Si Beaumont
2015-04-13 08:13:29 UTC
Permalink
Post by Si Beaumont
Post by Thomas Adam
+ update = options_get_string(&global_s_options, "update-environment");
I think you want &s->options here, no?
Ah, yes! Sorry I think I cribbed from the wrong place and what you say is what
happens in the attach command.
Attached is a revised version of the patch.
Is the patch in the previous message now acceptable?

Si
Nicholas Marriott
2015-04-13 09:52:53 UTC
Permalink
probably, thanks. it looks ok but i'm not sure if it is a good idea
Post by Si Beaumont
Post by Si Beaumont
Post by Thomas Adam
+ update = options_get_string(&global_s_options, "update-environment");
I think you want &s->options here, no?
Ah, yes! Sorry I think I cribbed from the wrong place and what you say is what
happens in the attach command.
Attached is a revised version of the patch.
Is the patch in the previous message now acceptable?
Si
------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
tmux-users mailing list
https://lists.sourceforge.net/lists/listinfo/tmux-users
Nicholas Marriott
2015-05-07 14:07:34 UTC
Permalink
Applied to OpenBSD now, will be in SF at next sync up. Thanks!
Post by Si Beaumont
Post by Thomas Adam
+ update = options_get_string(&global_s_options, "update-environment");
I think you want &s->options here, no?
Ah, yes! Sorry I think I cribbed from the wrong place and what you say is what
happens in the attach command.
Attached is a revised version of the patch.
Si
Post by Thomas Adam
From b572f6168f98cf8745f210dfe8eaa93ecc3e4704 Mon Sep 17 00:00:00 2001
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..a421573 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(&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
https://lists.sourceforge.net/lists/listinfo/tmux-users
Loading...