如何在当前环境下启动 tmux? [英] How do I start tmux with my current environment?

查看:31
本文介绍了如何在当前环境下启动 tmux?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

或者至少是其中的一部分,这是有道理的.

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

更具体地说,我有一些环境变量,它们是通过运行脚本导出的,以便为手头的任务创建适当的环境.当我运行 tmux 时,这些变量无处可见,无论是在全局环境还是会话环境中.当然我可以再次运行这个脚本但是...

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 ...

如果我可以在我的 .tmux.conf 文件中指定特定的变量,我会很满意:

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

set-environment VAR $VAR

不符合我的预期.

提前致谢:)

啊,我想我知道为什么了.

Ah, I think I know why.

当启动 tmux 的第二个会话时,比如在另一个终端中,它会从第一个终端复制环境.第一个几乎采用调用 shell 的当前环境并为其添加一些 tmuxiness.

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.

我目前的解决方法是在需要更改环境时停止和启动我的 tmux 会话.

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

推荐答案

您应该配置 tmux 会话选项 update-environment 以包含要更新的变量创建新会话时.默认值包括几个常见的 X11 和 SSH 变量:

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

要添加变量,请使用 set-option tmux 命令及其 -g-a标志(附加到现有的全局"(默认)值).在你的 ~/.tmux.conf 中:

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.

这篇关于如何在当前环境下启动 tmux?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆