Can one configure Tmux to load ~/.bashrc instead of ~/.bash_profile?

我的未来我决定 提交于 2019-12-13 15:13:37

问题


Right now, when I log in to Tmux, only ~/.bash_profile gets loaded.

I'd like ~/.bashrc to get called instead.

Is that possible?


回答1:


This issue is not related to tmux. To solve it make sure to add source ~/.bashrc to .bash_profile and that's it.

You can learn more about bash initialization and which files it loads and in which order here: https://github.com/sstephenson/rbenv/wiki/Unix-shell-initialization#bash

As you can see .bashrc is not even on the list when bash is started in login mode, that's why we source it from the file (.bash_profile) that is on the list.




回答2:


You can fix that at the tmux level by explicitly setting the default shell command:

tmux set-option default-command "/bin/bash"

From the tmux manual (emphasis mine):

         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.

As explained by Chepner in a comment below:

default-shell defaults to your preferred login shell; default-command defaults to starting a login instance, effectively $SHELL -l

... and in the case of Bash, a login shell doesn't read ~/.bashrc. By overriding the value of default-command, we can now force tmux to create a non-login shell instead.



来源:https://stackoverflow.com/questions/28464543/can-one-configure-tmux-to-load-bashrc-instead-of-bash-profile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!