【发布时间】:2012-03-11 03:19:35
【问题描述】:
tmux 启动或打开新窗口时,不会加载我的.profile 或.bashrc。我最终每次都输入. ~/.bashrc。有没有办法让这种情况自动发生?
【问题讨论】:
标签: tmux
tmux 启动或打开新窗口时,不会加载我的.profile 或.bashrc。我最终每次都输入. ~/.bashrc。有没有办法让这种情况自动发生?
【问题讨论】:
标签: tmux
是的,在您的.bash_profile 末尾添加以下行:
. ~/.bashrc
这会在通常只处理配置文件的情况下自动获取 rc 文件。
bash 何时运行某些文件的规则很复杂,取决于启动的 shell 类型(登录/非登录、交互与否等),以及命令行参数和环境变量.
您可以在 man bash 输出中看到它们,只需查找 INVOCATION - 不过您可能需要一些时间来消化和解码它 :-)
【讨论】:
.bashrc/.profile is not loaded on new tmux session (or window) — why?
以前的答案提供了解决方案,但没有解释原因。在这里。
这与 Bash 初始化文件有关。默认情况下,~/.bashrc 用于 交互式、非登录 shell。它不会在登录 shell 中获取。 Tmux 默认使用 login shell。因此,由 tmux 启动的 shell 会跳过 ~/.bashrc。
default-commandshell-command默认为空字符串,指示 tmux 使用
default-shell选项的值创建登录 shell。
Bash 的初始化文件,
/etc/profile~/.bash_profile、~/.bash_login、~/.profile(仅存在第一个)/etc/bash.bashrc(某些 Linux;不适用于 Mac OS X)~/.bashrc$BASH_ENV 中的源文件
奇怪的交互式、非登录加载要求在其他情况下也会让人们感到困惑。 最佳解决方案是将~/.bashrc的加载要求更改为仅交互,这正是某些发行版(如Ubuntu)正在做的事情。
# write content below into ~/.profile, or ~/.bash_profile
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
这应该是您想要的解决方案。我建议每个 Bash 用户在配置文件中进行设置。
参考文献
man tmux【讨论】:
通过将此行添加到我的 ~/.tmux.conf 文件中,明确地运行 bash 对我有用:
set-option -g default-command "exec /bin/bash"
【讨论】:
~/.tmux.conf 中添加了以下行:set -g default-command "/bin/bash"。谢谢老兄。
对我有用的解决方案如下:
~ 中没有文件,请创建.bash_profile 文件
.bash_profile 末尾放source ~/.bashrc 或source ~/.profile
这个问题现在应该已经解决了。
【讨论】:
【讨论】:
$echo case $- in *i*) . ~/.bashrc;; esac >> .bash_profile
我遇到了同样的问题,到目前为止的解决方案对我不起作用。可以找到最终为我工作的解决方案here。
简而言之,tmux windows/sessions 使用登录 shell,它在启动时在其他文件中查找 ~/.profile。
我想要让 zsh 从每个新的tmux 窗口开始,所以我将exec zsh 放在~/.profile 的底部。
【讨论】: