Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like my default bash shell to go straight into tmux instead of my always having to type tmux every time.

share|improve this question

6 Answers 6

up vote 8 down vote accepted

This seems to work...

https://wiki.archlinux.org/index.php/Tmux#Start_tmux_on_every_shell_login

Simply add the following line of bash code to your .bashrc before your aliases; the code for other shells is very similar:

[[ $TERM != "screen" ]] && exec tmux
share|improve this answer
4  
Please don't post answers that are just links to other pages; at least summarize what it says –  Michael Mrozek Jul 20 '12 at 17:32
    
For me this also required [[ $- != *i* ]] && return to not being an infinite loop (from the same page) –  Keith Smiley Apr 14 '13 at 1:45

@StarNamer's answer is generally accurate, though I typically include the following tests to make sure that tmux (1) exists on the system and (2) doesn't try to run within itself:

if command -v tmux>/dev/null; then
  [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux
fi
share|improve this answer

There is command chsh which changes login shell. Consult man chsh.

share|improve this answer
2  
tmux is not a shell, it's a terminal multiplexer like GNU screen. Interestingly, it does support the -c option according to the man page, so it may work like a shell just enough to use it as your login shell, but I suspect it won't work properly in all situations, e.g. graphical logins via gdm/kdm. –  Mikel Jul 20 '12 at 15:32
    
Although this is sensible and backed by the documentation, it seems to break direct command execution via SSH (something like ssh $some_server echo foo). –  n.st May 11 at 2:11

I'm successfully using

case $- in *i*)
    [ -z "$TMUX" ] && exec tmux
esac

in my .zshrc. If you're using bash, put it in your .bashrc instead.


I also just tried setting tmux as my default shell (chsh -s $(which tmux)) and it seems to break direct command execution via SSH, e.g. ssh $some_server echo foo will not produce any output.

share|improve this answer

Add this into your ~/.tmux.conf

set -g default-command /usr/local/bin/fish
share|improve this answer

As Mikel already stated in his comment to have tmux as your login shell can have side effects. But you can make tmux your default shell, literally. A user's default shell is defined in /etc/passwd. So you can become root and edit /etc/passwd, e.g. sudo vi /etc/passwd search for the line that begins with your username. It probably ends with :/bin/bash. Change /bin/bash to /usr/bin/tmux and now tmux is your default login shell.

However, no guarantee that this won't cause problems!

What may work better is to NOT do anything that requries root privileges. I would try to create a file in my home directoy named .bash_login and start tmux from within that file: `echo "tmux" >~/.bash_login.

This should work, but you have to try and find our yourself, b/c the bash documentation is not very exact about what file is read and executed when.

share|improve this answer
1  
What your first paragraph describes is what chsh does! Except that your way requires being root and is error-prone. Running tmux from .bash_login is more likely to break remote logins. –  Gilles Jul 20 '12 at 23:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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