How do I start tmux with my current environment? [closed]

左心房为你撑大大i 提交于 2019-12-03 03:37:43

问题


Or at least the part of it, that makes sense.

More specifically I have some environment variables, that have been exported by running a script, to create an adequate environment for the task at hand. When I run tmux these variables are nowhere to be seen, neither in the global or the session environment. Of course I can run this script again but ...

I'd be satisfied if I could specify the particular vars in my .tmux.conf file however:

set-environment VAR $VAR

Does not do what I'd expect.

Thanks in advance :)

Ah, I think I know why.

When starting a second session of tmux, say in another terminal, it copies the environment from the first one. The first one pretty much takes the current environment of the calling shell and adds some tmuxiness to it.

My current workaround is just stopping and starting my tmux sessions when i need to change environment.


回答1:


You should configure the tmux session option update-environment to include the variables you want to be updated when creating new sessions. The default value includes several common X11 and SSH variables:

DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY

To add your variables, use the set-option tmux command with its -g and -a flags (append to the existing “global” (default) value). In your ~/.tmux.conf:

set-option -ga update-environment ' YOUR_VAR'

Be sure to include the leading space so that your variable name is separated from the trailing name in the default value.



来源:https://stackoverflow.com/questions/8645053/how-do-i-start-tmux-with-my-current-environment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!