我的 .bash_profile 中有一个脚本,提示 X 会话启动。当我启动 tmux 时,我得到这个提示,我只打算用于 TTY 登录。
如果 .bash_profile 是 tmux 的一部分,那么我可以在 .bash_profile 中放入一些东西吗?也就是说,如果 .bash_profile 在 tmux 中被读取,我可以用 bash 检查吗?
J.C*_*ski 12
tmux 设置了一个名为 的环境变量$TMUX
,我相信它保存了它正在使用的套接字的位置。无论哪种方式,您都可以在您.bash_profile
的测试中使用它来测试它是否在 tmux 中被调用。
if [ -z "$TMUX" ]; then
# not in tmux, do non-tmux things
fi
Run Code Online (Sandbox Code Playgroud)
或者
if [ -n "$TMUX" ]; then
# called inside tmux session, do tmux things
fi
Run Code Online (Sandbox Code Playgroud)