Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using tmux loses all my bash aliases, how can I get them to stay?

Tags:

alias

bash

rvm

tmux

My .bashrc does

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

which includes runs my .bash_aliases and gives me a ton of aliases that I've defined.

However if I try and use TMUX (invoked with tmux) the only alias I now have is:

$ aliasreturn # will show....

$ alias rvm-restart='rvm_reload_flag=1 source '\''/home/durrantm/.rvm/scripts/rvm'\'''

How can I use tmux and still have all my aliases available.

I'm on Ubuntu 12.04

The end of my .bashrc file looks like this:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# Automatic cd'ing
shopt -s autocd

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM

export EDITOR=vim

git config --global --add color.ui true
like image 667
Michael Durrant Avatar asked Apr 25 '13 20:04

Michael Durrant


People also ask

Where are my bash aliases?

Check Bash Aliases in LinuxInvoke your shell and simply type “alias” to see the list of defined alias. User-level aliases can be defined either in the . bashrc file or the . bash_aliases file.

Does Tmux run Bashrc?

Tmux uses a login shell by default. Hence, shells started by tmux skip ~/. bashrc . The default is an empty string, which instructs tmux to create a login shell using the value of the default-shell option.

How do bash aliases work?

Bash aliases allow you to set a memorable shortcut command for a longer command. Bash aliases are essentially shortcuts that can save you from having to remember long commands and eliminate a great deal of typing when you are working on the command line.


2 Answers

tmux invokes your shell as a login shell. Login shells don't process .bashrc, but use .bash_profile instead.

You can simply make .bash_profile read your .bashrc:

echo 'source ~/.bashrc' >> ~/.bash_profile
like image 176
that other guy Avatar answered Oct 13 '22 15:10

that other guy


It would be better simply run bash in tmux once the pane is "started". There is a difference btw login and interactive shells for a reason. I would rather search for a way to run a command in every newly created pane.

like image 1
Horror Vacui Avatar answered Oct 13 '22 15:10

Horror Vacui