Instead of having to type tmux
every time, how could I have tmux
always be used for new session windows?
So if I have no terminal windows open and then I open one, how can that first session be in tmux
?
Seems like a .bashrc
sort of thing perhaps?
My original, accepted answer, stopped working on my Ubuntu14 system after a recent upgrade.
Using either
or
would stop me from being able to even login. I was only able to resolve this due to having a second admin login on the computer.
The fix for me on Ubuntu (and in osx too) was to change my terminal program to actually run tmux instead, i.e.
I still have
as my last
.bashrc
line but that his only for my Mac OSX systems now.If you want to have a single tmux session, put the following in your ~/.bashrc for bash or ~/.zshrc for zsh:
The
tmux attach
line is to make sure if there is a session it attaches to and if there was no session you will not get the warning about "no session".I just made it a keyboard shortcut (in Linux Mint not Ubuntu; so I'm not sure if it is this easy)...
It might be hard to see, but the custom shortcut is
gnome-terminal --window --maximize -e tmux
. This starts a newgnome-terminal
window maximized and thenexec
utestmux
for you.I additionally have another custom shortcut that starts a "normal"
gnome-terminal
maximized (it's the same without the-e tmux
).I feel this is the best way because you can start whatever terminal whatever way you want and is the most customizable way.
To enable tmux for login and ssh sessions, you can add this to the end of your .bashrc:
This script looks for the parent process of the bash shell. If bash was started from logging in or from ssh, it will execute tmux. If you want this to work with a GUI terminal, you can add that in there as well. For example, if you want to start tmux automatically when you start Ubuntu's standard
gnome-terminal
, you would use this:I've tested the above on Live Ubuntu Desktop and I was able to log in afterwards. This should not break the GUI login unless it invokes the login command to log in. I am not aware of a linux GUI that does this.
Append following line of code to the end of
.bashrc
,A one-liner that also makes sure the terminal type is set correctly for 256 colors: