Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.bashrc/.profile is not loaded on new tmux session (or window) -- why?

Tags:

tmux

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?

like image 615
John Smith Avatar asked Mar 11 '12 03:03

John Smith


People also ask

Does tmux use Bashrc?

Tmux uses a login shell by default. Hence, shells started by tmux skip ~/. bashrc .

How do I create a new tmux session from your current tmux session?

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.

What is the difference between Bashrc and profile?

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 .

When Bashrc is executed?

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.


1 Answers

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 :-)

like image 61
paxdiablo Avatar answered Oct 21 '22 14:10

paxdiablo