Efficient terminal setup with alacritty and tmux

Kavishka Gihan
7 min readOct 4, 2022

--

Recently, I thought of upgrading my terminal to be able make it more convenient and user-friendly. Since I am an active CTF player and a content creator, I wanted to be able to get the best of my setup. There are couple of things which changed my whole terminal experience. So today, I will be walking you through what they are and maybe you can adapt some of them too.

Alacritty Terminal Emulator

Back when I started with all this, I was using terminator as my terminal emulator which was fine at that time. But after I switch to i3 (inherited from xct’s setup) it was time for me to switch to another terminal emulator. That’s when I heard about alacritty

Alacritty is a light-weight, cross platform terminal emulator which provides a ton of customization options. Once of the things I love about this is that it is very fast and smooth. Since my setup is inside a Virtual Machine, I try my best to run things as smooth as possible. So this is a perfect fit for me.

You can install it with the following commands

sudo add-apt-repository ppa:aslatter/ppa
sudo apt update
sudo apt install alacritty

As I mentioned, there is a ton of customization that can be done. You can find my config from here

Tmux

Tmux by itself stands for terminal multiplexer. But except terminal multiplexing, it is capable of doing lot more things. Personally, I didn’t like it in the past as it makes most of the shortcut keys and functionalities complex than it should be. But now I am really loving it because of the power it possess and how easily configurable it is.

To install it, run:

sudo apt install tmux

Like alacritty, this has a vast variation of customization options that you can use. My tmux setup looks like this.

You can find my full config from here

Useful tmux keybindings and commands

There are tons of shortcuts that we could talk about tmux like window management, pane management and etc. You can find most of them here.

But here despite the usual stuff, I will be talking about some unpopular but yet useful shortcuts.

1. Synchronized panes

With synchronized panes, you can send commands to multiple panes once. For example, say I have to connect to a remote machine with ssh. Typically, I do need multiple terminals to get most of my work done. So instead of logging into the machine 3 times, you can sync 3 panes and just login once which will be synced to all the other 3 terminals at the same time.

bind-key g set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}"

As you see, I have set the keybinding to be <prefix>+g Once pressed, it will show such a message.

Now you can start typing, it will be synced to all the panes you have in the current window.

2. Copy mode

The typical way I used to copy text was by using my mouse to select the text and then using Ctrl+shift+c But personally, I try my best to keep away from the mouse and to do everything from my keyboard. That’s where this came in handy.

setw -g mode-keys vi

This enables the mode keys for vi editor, which enables us to select and copy commands from the terminal. The default keybinding to launch it is <prefix>+[

You can use your space bar and arrow keys to select text. Once done selecting, press Enter and the contents will be copied to your clipboard.

3. Status bar for Note-taking

Default tmuxstatus bar has information like the number of windows, window names, hostname, time etc. But I don’t need most of them. So I have configured it to only show the session ID and the windows. Also I have changed the color scheme.

set-option -g status-style bg=color234,fg=color244                             set-option -g status-left ''                             
set-option -g status-right '[#{session_name}]' set-option -g window-status-format '#{window_index}' set-option -g window-status-current-format '#[bold, fg=white]#{window_index}'

Since I had so much space left in the status bar, I thought of using it for something helpful. So I added some aliases to my .zshrc which will allow me to add text to the status bar.

tsa() {
status_bar=$(cat $TMUX_SATUS_BAR)
tmux set-option -g status-right "$1 $status_bar"
echo "$1 $status_bar" > $TMUX_SATUS_BAR
}
tsd() {
echo '[#{session_name}]' > $TMUX_SATUS_BAR
status_bar=$(cat $TMUX_SATUS_BAR)
tmux set-option -g status-right "$status_bar"
}

NOTE: For this to work you need to have a variable called TMUX_SATUS_BARpointing to a file which contains the current config for your the right side if your status bar. For me its [#{session_name}]. For more information, take a look at my .zshrc

One useful example of this would be when you have a complex password for a remote user account, you don’t have to type it out or go get it from a text file, you can just add it to your status bar so that you can copy it anytime you need.

If you want to clear these,use tsd and it will be back to your config default.

Also you can use this to note down your IP of your network interface if you use it often. Since I have i3 blocks, I don’t need to do that, but it is possible. This would an example for that.

set -g status-right "eth0: #(ifconfig eth0|grep inet|head -n 1|awk  '{ print $2 }')"

4. Automating tmux

This is something I was really impressed with. Back when I used terminator, when I was getting ready for a task that requires multiple windows, I had to manually get the terminals setup.

For example, when I start with an HTB box, I first connect my vpn, then I create the base directory for the box and make some sub-directories to stay organized. I then setup my terminal with 3–4 windows, placing vertically and horizontally divided panes to my need. This is very time consuming. But with tmux all I have to do it run one simple command and it will do everything for me.

I have an alias in my .zshrc called htb-setup which will run a script to set all these up with tmux

Now I just have to do htb-setup <Box name>

First it starts a tmux session named htb Then it creates 4 windows win1,win2,win3 and vpn inside the htb session. The 1st window will have 3 panes according to the main-vertical layout of tmux.

The 2nd pane will have 2 vertically divided panes.

3rd and 4th windows will have only one pane. In the 4th window, openvpn will be running to connect to the HTB’s VPN.

This is just my setup, you can make this do whatever you need. If you want, you can have this run your initial scans like nmap and gobuster as well.

One more cool thing about tmux is that, once you are done, you can just close your terminal. And if you want to get back to it, all you have to do is reattach to the session with tmux attach -t htb and all your work will be there safe and sound.

As you can see, with the correct knowledge tmux can be used to do very powerful things. As mentioned I used to not like tmux because of it’s complexity but once you get to know them, you almost get addicted to it.

With these 2 upgrades, I have increased my usual speed inside my setup tremendously. I also added some things like ranger to help with file managing which is really nice as well. So far this is, one of the best setups I have ever had!

--

--

Kavishka Gihan

Cyber Security Student | Machine author @hackthebox | find me on instagram @_kavi.gihan