Already use *nix CLI? Do you wish that you could empower yourself to be the stereotypical hacker seen on television enhancing images and hacking the mainframe? Get ready, because here you are.
Tmux is an open-source cli app that allows multi-tasking and having multiple terminals on the same screen - even on remote machines. For the fancy folk, a "Terminal multiplexer".
First things first, let's get it installed.
brew install tmux
sudo port install tmux
sudo apt-get install tmux
yum install gcc kernel-devel make ncurses-devel
curl -OL https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz tar -xvzf libevent-2.0.21-stable.tar.gz cd libevent-2.0.21-stable ./configure --prefix=/usr/local make sudo make install
Download and install tmux:
curl -OL https://github.com/tmux/tmux/releases/download/2.2/tmux-2.2.tar.gz tar -xvzf tmux-2.2.tar.gz cd tmux-2.2 LDFLAGS="-L/usr/local/lib -Wl,-rpath=/usr/local/lib" ./configure --prefix=/usr/local make sudo make install
First up, let's start up tmux (assuming you installed it already) by simply issuing
tmux in your terminal.
The only thing you'll notice first-off is a bar at the bottom of your terminal, but nothing else seems to have changed. And you'd technically be right. It shouldn't impede your typical terminal activities at all.
To actually begin issuing commands to tmux, you'll need to use tmux's hot-key. By default, this is
Ctrl+b. You won't see any indication that the hotkey is active, but by issuing
", you'll find that your terminal has divided into two!
↑ will allow you to switch back to your old window, and the opposite goes for
↓ (these do wrap, so pressing
↑ twice will place you back on your starting window).
To close a window, simply exit out of your terminal as you usually might, by typing
x. This will place you in your nearest split terminal, or exit out of tmux if it's the last open window.
Splitting horizontally is cool, but know what's really cool? Splitting vertically. To split vertically, it's the same idea:
%. That should provide you with something like this:
Moving between these panes is as easy as moving among horizontally split panes. Simply issue the
"This is all cool, but I'm used to screen - I like entire new windows."
I gotchu. Completely understandable, and tmux has that capability.
The command you're looking for is
c to create a new "window" as they're called. To cycle through panes, use
p (for next and previous windows, respectively).
To rename a pane, use
,, then you'll find yourself editing the name of the window in the bar with the asterisk (
*) beside it:
Things getting too crazy with your splitting panes? Use
space to toggle standardized layouts.
tmux utilizes sessions - a new (automatically named) session is created upon running
tmux, and you work within it from there. There can be multiple sessions running on the same machine in harmony, but be wary of nesting sessions as it can lead to some unexpected behavior.
To see all the tmux sessions on a machine, use
Connecting to a session is as easy as
tmux a <session name>.
To create a new session with a human-readable name, use
tmux new -s <session name>, and to destroy a session:
tmux kill-session -t <session name>.
Whilst in a tmux session, you can disconnect without halting or exiting the current terminal by issuing
Ctrl+b is terribly straining on your hands if you use it often, it's simply not an intuitive hotkey, and everything else close to the
Ctrl key seems to be spoken-for. Here's how to get around that. For our example, we'll remap the hotkey to
Create a settings file with
touch ~/.tmux.conf and open it up for editing with your favorite editor.
Now we'll want to add the following line:
set-option -g prefix C-d - where
C is Ctrl, and d is the
d key. These can be set to any key combination you prefer. In this case, I've remapped my
Ctrl+d, and can't send a
Ctrl+d to the terminal anymore. We can fix this by adding
bind-key C-d send-prefix. This will allow a second
Ctrl+d issued to pass through to the terminal beneath tmux.
This is a high-level overview meant to get you acquainted with the basics of tmux - there's a lot that isn't covered here. At a later time, we'll post a full-on cheat-sheet for your viewing pleasure.
man tmux and stay Brave, people.