Aliases defined in .bash_aliases and .bashrc don't work in tmux.

Can this be changed in some configuration, so the aliases work under tmux?

  • 2
    Are you sure problem is in tmux? I use tmux about year and haven't seen any problems with aliases. Try to add set -x at the begin of your .bashrc and run in tmux command source ~/.bashrc . May be you'll find any errors and it will solve your problem. – rush May 11 '12 at 11:34

tmux launches a login shell by default, so ~/.bashrc will not be executed (which then subsequently sources ~/.bash_aliases. You need to source ~/.bashrc from your ~/.bash_profile. See the INVOCATION section of man bash.

| improve this answer | |

(Chris Down's answer has the right explanation but not a good workaround)

Your problem stems from a combination of a bash design bug and a tmux design bug.

By default, tmux starts a login shell in every window. This doesn't make any sense: if you've set tmux as your login shell, you need to set the default-command option to something other than tmux; and if you haven't set tmux as your login shell, you need to set the default-command option to avoid starting a login shell inside tmux. So pout this in your ~/.tmux.conf to tell tmux to start an ordinary shell:

set-option -g default-command $SHELL

Then your .bashrc will be read. There is another issue with bash, which doesn't matter here if you configure tmux as recommended above, but which will surface again if you log in in text mode (on a text console, or over SSH). Bash reads ~/.bash_profile in login shells, and ~/.bashrc in interactive shells but only if they are not login shells. To read ~/.bashrc also in login shells if they're interactive, add this to your ~/.bash_profile:

case $- in *i*) . ~/.bashrc;; esac
| improve this answer | |
  • +! It took that last part to get my aliases and PS1 prompt fixed, but it did! – Michael Durrant Jun 3 '12 at 1:49

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.