可以将 Tmux 配置为加载 ~/.bashrc 而不是 ~/.bash_profile 吗?
Can one configure Tmux to load ~/.bashrc instead of ~/.bash_profile?
现在,当我登录 Tmux 时,只有 ~/.bash_profile
被加载。
我希望 ~/.bashrc
被叫到。
这可能吗?
此问题与 tmux
无关。要解决它,请确保将 source ~/.bashrc
添加到 .bash_profile
即可。
您可以在此处了解有关 bash
初始化及其加载的文件和加载顺序的更多信息:https://github.com/sstephenson/rbenv/wiki/Unix-shell-initialization#bash
如您所见,当 bash 在登录模式下启动时,.bashrc
甚至不在列表中,这就是我们从打开的文件 (.bash_profile
) 获取它的原因列表。
您可以通过显式设置默认 shell 命令在 tmux
级别修复此问题:
tmux set-option default-command "/bin/bash"
来自 tmux
手册(强调我的):
default-command shell-command
Set the command used for new windows (if not specified
when the window is created) to shell-command, which may
be any sh(1) command. The default is an empty string,
which instructs tmux to create a **login shell** using the
value of the default-shell option.
default-shell path
Specify the default shell. This is used as the login
shell for new windows when the default-command option is
set to empty, and must be the full path of the exe‐
cutable. When started tmux tries to set a default value
from the first suitable of the SHELL environment vari‐
able, the shell returned by getpwuid(3), or /bin/sh.
This option should be configured when tmux is used as a
login shell.
Chepner 在下面的评论中解释道:
default-shell
defaults to your preferred login shell;
default-command
defaults to starting a login instance, effectively
$SHELL -l
... 在 Bash 的情况下,login shell 不会读取 ~/.bashrc
。通过覆盖 default-command
的值,我们现在可以强制 tmux
创建一个 非登录 shell。
现在,当我登录 Tmux 时,只有 ~/.bash_profile
被加载。
我希望 ~/.bashrc
被叫到。
这可能吗?
此问题与 tmux
无关。要解决它,请确保将 source ~/.bashrc
添加到 .bash_profile
即可。
您可以在此处了解有关 bash
初始化及其加载的文件和加载顺序的更多信息:https://github.com/sstephenson/rbenv/wiki/Unix-shell-initialization#bash
如您所见,当 bash 在登录模式下启动时,.bashrc
甚至不在列表中,这就是我们从打开的文件 (.bash_profile
) 获取它的原因列表。
您可以通过显式设置默认 shell 命令在 tmux
级别修复此问题:
tmux set-option default-command "/bin/bash"
来自 tmux
手册(强调我的):
default-command shell-command Set the command used for new windows (if not specified when the window is created) to shell-command, which may be any sh(1) command. The default is an empty string, which instructs tmux to create a **login shell** using the value of the default-shell option. default-shell path Specify the default shell. This is used as the login shell for new windows when the default-command option is set to empty, and must be the full path of the exe‐ cutable. When started tmux tries to set a default value from the first suitable of the SHELL environment vari‐ able, the shell returned by getpwuid(3), or /bin/sh. This option should be configured when tmux is used as a login shell.
Chepner 在下面的评论中解释道:
default-shell
defaults to your preferred login shell;default-command
defaults to starting a login instance, effectively$SHELL -l
... 在 Bash 的情况下,login shell 不会读取 ~/.bashrc
。通过覆盖 default-command
的值,我们现在可以强制 tmux
创建一个 非登录 shell。