13

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?

1
  • 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, 2012 at 11:34

2 Answers 2

22

(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 put the following 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
1
  • +! It took that last part to get my aliases and PS1 prompt fixed, but it did! Jun 3, 2012 at 1:49
9

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .