Bash – New tmux sessions do not source bashrc file

bashtmux

Summary

When I create a new tmux session, my prompt pulls from a default bash configuration and I have to manually run source ~/.bashrc for my customized prompt.

Analysis

I am using a RHEL 7 machine. I began noticing this behavior after a bash update a while back, but haven't gotten around to asking the question until now (and am not sure which update this began happening around).

For example, I've customized my prompt to look like:

[user@hostname ~]$

Whenever I start a new tmux session, it uses what appears to be the bash default:

-sh-4.2$

A quick run of source ~/.bashrc always fixes the issue, but it's annoying that I have to do this every time I want to fix something small. Any ideas on how to get tmux to do this automatically again?

If any more information is needed, I am happy to provide.

tmux.conf

For reference, I have my tmux.conf file below, although it is hardly what you could call custom.

setw -g mode-keys vi

# reload tmux.conf
bind r source-file ~/.tmux.conf \; display-message " ✱ ~/.tmux.conf is reloaded"

Best Answer

As far as I know, by default tmux runs a login shell. When bash is invoked as an interactive login shell, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile. So you have to put source ~/.bashrc in one of those files.

Another way to solve this issue is to put in your file .tmux.conf the line:

set-option -g default-shell "/bin/bash"
Related Question