可以配置 Tmux 来加载 ~/.bashrc 而不是 ~/.bash_profile 吗?

Kam*_*Kam 4 linux tmux

现在,当我登录到 Tmux 时,只会~/.bash_profile加载。

我想~/.bashrc换个电话。

那可能吗?

小智 8

这个问题与 无关tmux。要解决它,请确保添加source ~/.bashrc.bash_profile,仅此而已。

您可以bash在此处了解有关初始化以及加载哪些文件以及加载顺序的更多信息: https: //github.com/sstephenson/rbenv/wiki/Unix-shell-initialization#bash

正如您所看到的,.bashrc当 bash 以登录模式启动时,它甚至不在列表中,这就是我们从.bash_profile列表中的文件 ( ) 获取它的原因。


Syl*_*oux 5

您可以tmux通过显式设置默认 shell 命令来修复该级别:

tmux set-option default-command "/bin/bash"
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)

正如 Chepner 在下面的评论中所解释的那样:

default-shell默认为您首选的登录 shell; default-command默认启动登录实例,有效 $SHELL -l

...而在 Bash 的情况下,登录shell 不会读取~/.bashrc. 通过覆盖 的值default-command,我们现在可以强制tmux创建一个非登录shell。