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 script for fast window switching with fzf-tmu
- TMUX Session Won't Import Python Module
- How to get stdout and stderr from a tmux session?
- iTerm 2 not honoring key bindings declared in .tmu
- Vim + tmux + WSL shows squares and strange charact
相关文章
- Tmux: how do I bind function keys to commands?
- Find tmux session that a PID belongs to
- Configure tmux scroll speed
- Alert in tmux when a process completes
- With $TERM='screen-256color' under tmux, H
- How to copy from tmux running in putty to windows
- How to copy from tmux running in putty to windows
- In tmux can I resize a pane to an absolute value
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
.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_ENV
The 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.This should be the solution you desire. And I recommend every Bash user setup this in the profile.
References
man tmux
The solution that worked for me is the following:
.bash_profile
file if you don't have one in~
.bash_profile
putsource ~/.bashrc
orsource ~/.profile
The issue should now be fixed.
Running bash explicitly worked for me, by adding this line to my ~/.tmux.conf file:
From this thread:
seems using
.bash_profile
would work.Yes, at the end of your
.bash_profile
, put the line: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 forINVOCATION
- you'll probably need some time to digest and decode it though :-)I had the same problem and the solutions so far didn't work for me. The solution that ended up working for me can be found here.
In short,
tmux
windows/sessions use a login shell which looks for a~/.profile
among other files when it starts.What I wanted was to have zsh start with each new
tmux
window so I putexec zsh
at the bottom of my~/.profile
.