13

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"
14

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"
  • 1
    I added the source ~/.bashrc line to my .bash_profile, tried logging out and back in, create a new tmux session, but no change. Any ideas? – Justin W. Flory Nov 8 '16 at 2:52
  • 1
    Try to put in your file .tmux.conf the line set-option -g default-shell "/bin/bash". This should solve your issue (at least I hope so)! – andreatsh Nov 8 '16 at 22:06
  • After reloading my tmux configuration, this solved my issue! Want to modify your answer or create a new one? I would be happy to mark it as accepted. :) – Justin W. Flory Nov 17 '16 at 4:24
  • You're kind, I quickly modified my answer! – andreatsh Nov 17 '16 at 15:08
  • Note for macOS users: if you've installed bash via Homebrew and this doesn't work, change "/bin/bash" to "/usr/local/bin/bash". – glhrmv Apr 5 '18 at 14:48
0

Simple Solution

mv .bashrc .bashrc_profile
  • 1
    This is not a solution. .bashrc is for interactive shells, and ,bash_profile is for login shells. If you have anything that produces output in .bash_profile (like uptime or calendar), this may cause issues with e.g. ssh under certain circumstances. – Kusalananda May 31 '18 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.