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
Former answers provided solutions but didn't explain the reason. Here it is.
This is related to the Bash init files. By default, ~/.bashrc is used in an interactive, non-login shell. It won't be sourced in a login shell. Tmux uses a login shell by default. Hence, shells started by tmux skip ~/.bashrc.
default-commandshell-commandThe default is an empty string, which instructs tmux to create a login shell using the value of the
default-shelloption.
Init files for Bash,
/etc/profile~/.bash_profile, ~/.bash_login, ~/.profile (only first one that exists)/etc/bash.bashrc (some Linux; not on Mac OS X)~/.bashrc$BASH_ENVThe weird interactive, non-login loading requirement confuses people in other situations as well. The best solution is to change the loading requirement of ~/.bashrc as interactive only, which is exactly what some distros, like Ubuntu, are doing.
# write content below into ~/.profile, or ~/.bash_profile
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
This should be the solution you desire. And I recommend every Bash user setup this in the profile.
References
man tmux