When tmux starts or opens a new window, it does not load my .profile
or .bashrc
. I end up typing . ~/.bashrc
every time. Is there a way to make this happen automatically?
Tmux uses a login shell by default. Hence, shells started by tmux skip ~/. bashrc .
Using the Prefixes to Control Tmux By default, the prefix is CTRL+B. That is, we have to press the keys CTRL+B and then the command. For example, to create a new session, the command would be C. So, to create a new session we need to press CTRL+B and next C – CTRL+B, C.
bash_profile is read and executed when Bash is invoked as an interactive login shell, while . bashrc is executed for an interactive non-login shell. Use . bash_profile to run commands that should run only once, such as customizing the $PATH environment variable .
bashrc is executed before the window command prompt. . bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal. On OS X, Terminal by default runs a login shell every time, so this is a little different to most other systems, but you can configure that in the preferences.
Yes, at the end of your .bash_profile
, put the line:
. ~/.bashrc
This automatically sources the rc file under those circumstances where it would normally only process the profile.
The rules as to when bash
runs certain files are complicated, and depend on the type of shell being started (login/non-login, interactive or not, and so forth), along with command line arguments and environment variables.
You can see them in the man bash
output, just look for INVOCATION
- you'll probably need some time to digest and decode it though :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With