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

时间:2015-02-11 21:10:06

标签: linux tmux

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

我希望~/.bashrc被调用。

这可能吗?

2 个答案:

答案 0 :(得分:4)

此问题与tmux无关。要解决此问题,请务必将source ~/.bashrc添加到.bash_profile以及它。

您可以详细了解bash初始化及其加载的文件以及此处的顺序:https://github.com/sstephenson/rbenv/wiki/Unix-shell-initialization#bash

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

答案 1 :(得分:4)

您可以通过显式设置默认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默认为您首选的登录shell;   default-command默认有效地启动登录实例   $SHELL -l

...对于Bash,登录 shell不会读取~/.bashrc。通过覆盖default-command的值,我们现在可以强制tmux来创建非登录 shell。