Why TMUX is cool!
Hello all, in this post I am not going to show how you could install tmux or how to configure it, those things are well documented on the net.
So, what you need is duckduck it and you will see a lot of tutorials..
What I am going to write here is the power of tmux and why every developer/sysadmin need it.
First of all, why they call it TMux?
It is because T stand for Terminal and Mux for Multiplexer.
Based on WiKipedia Multiplexer means one thing do a lot of different things..
OK, so let's begin with
what I like the most in tmux is that supports both vertical and horizontal splits whereas GNU Screen only supported one of the two.
One of the other reasons too, is for pair programming.
Let's say you are working with a big team and all persons need to look how you code in the real time.. It would be much better to all SSH into a single box and watch you edits code.
Rather than crowding around your laptop, which isn't feasible given the seating arrangements at play.
The final and the most important reason for me is long running processes on random servers. I have a VM with an Ubuntu install for various things (testing, packaging, etc..),
I have a tmux session which helps provide me context from one editing session to another.
Tmux is also a boon when dealing with a flaky wifi connection. Being able to resume the in-progress terminal screen is nice, so you don't have orphaned processes when your connection dies.
Terminal multiplexers have a command mode in which you can tell it to do something, such as switching virtual consoles or creating new ones.
In tmux the short-cut key to this command mode, called the prefix, is by default Ctrl-b, but if you want to change it, very simple just add the following to your ~/.tmux.conf
# Set the prefix to ^A
set -g prefix ^A
# So that you can go to the beginning of the line with ^A a
bind a send-prefix
Ctrl-a is in my opinion also easier to reach than Ctrl-b.
So, I will use Ctrl-a as the prefix key in the rest of this article. It will be shown as ^A.
Now that you are ready to use tmux, start it up. I make it a habit to give each tmux session a name, so that I can easily re-attach it by using the name:
$ tmux new -s base
In this example, I have called the tmux session "base".
But rather than executing this command everytime when you open your terminal, you add this line to your ~/.zshrc if you are using ZSH or ~/.bashrc if you are using BASH
tmux attach -t base || tmux new -s base
Allright, so let's say you want to create some virtual consoles. Hit
^A c. In the status bar, you will see that you have created another virtual console, with bash/zsh running in it.
The * means that that one is currently shown. Start any CLI tool and the name of your virtual console will change depending to what you have opened.
I think you are wondering I wanna set up a uniq name to my virtual console! Yep you can hit
^A , and rename it! :D
So, now I have more then one virtual console, how can I switch from one to another? Simply to switch hit
^A p or
The letters stand for previous and next console. Likewise, you can switch using numbers
^A 0 for the 1st console and 1 for the 2nd etc..
In Tmux also you can split windows vertically and horizontally using the prefix which is
^A and % for vertical split and " for horizontal split.
To navigate through spliw windows, you can use
^A o but I prefer using
^A arrow keys
Resizing the split windows is pretty easy also, keep the Control key pressed and use you the arrow keys to resize the currently focused spliw window
One of the great features of Tmux is that you can deattach and reattach your tmux session whenever you want!
Deattaching it simply with
^A d and if you want to reattach it, remember the name of the dettached session, if you forgot it is okay!
tmux ls will list yo you all your tumux sessions
then like I mention above to reattach it
tmux attach -t name_of_your_session
Allright, I will stop here and I will try to post another article about advanced/further customizations.
I am trying to keep this article short and not boring as it is :P
That's it, thank you for reading and feel free to send me a mail if you noticed that there's a typos or something is not enough clear!