Post

Boost Your Terminal Workflow with Zellij - The Next-Gen Terminal Workspace

In the world of terminal workspaces and multiplexers, one tool stands out for its simplicity, power, and ease of use—Zellij. As an SRE constantly juggling multiple terminal windows for monitoring, debugging, and development, I was looking for a way to streamline my workflow. Enter Zellij—a game-changer that simplifies my daily tasks, boosts productivity, and has now become my go-to terminal companion. In this post, I’ll share my experience and show you how Zellij can transform the way you work with terminal sessions.

Meet Zellij: A Modern Terminal Workspace

Zellij describes itself as a terminal workspace with “batteries included.” It’s a terminal multiplexer like Tmux or GNU Screen, but with a modern, user-friendly approach that makes it much easier to use and configure. Terminal multiplexers allow you to manage multiple terminal sessions within a single window, enabling you to organize your workflow, switch between tasks, and keep your environment tidy. Zellij takes this concept a step further by offering a built-in configuration, intuitive shortcuts, and the ability to detach and reattach sessions without losing your work.

Why Zellij Outshines Traditional Multiplexers

For those who spend a lot of time working in the terminal, navigating through different projects, or managing development environments, a terminal multiplexer is essential. But unlike traditional multiplexers like Tmux, Zellij offers several advantages:

  1. Ease of Use: Zellij is designed to be accessible. If you’re new to terminal multiplexers, the intuitive interface and helpful shortcuts will guide you through the basics.
  2. Default Shortcuts & Configurations: Out-of-the-box, Zellij provides a solid default configuration that you can start using immediately. Most users, myself included, rarely feel the need to tweak it.
  3. Floating Panes: One of Zellij’s unique features is its use of floating panes. These panes appear for temporary tasks, such as running a build or monitoring a process, and disappear once they are no longer needed.
  4. Seamless Layouts: Creating complex layouts with multiple panes and tabs is simple in Zellij. Define your preferred layout once, and you can reuse it whenever you start a new session.

Unleashing Zellij’s Key Features

1. Session Management

With Zellij, you can easily create new sessions, split them into multiple panes, and navigate through them using keyboard shortcuts. When working on complex projects like building a Golang application or managing multiple services, session management is critical. You can keep separate sessions for development, testing, and monitoring, making it easier to switch contexts without losing focus.

2. Detach and Reattach

Zellij allows you to detach from a session and reattach to it later, preserving the state of all your running processes. This is perfect for long-running tasks that you want to leave unattended. Simply detach, and when you’re ready to come back, reattach and continue where you left off.

3. Floating Panes

Unlike traditional terminal multiplexers, Zellij offers floating panes that can temporarily appear for specific tasks. For example, if I’m running a build process, I can have a floating pane showing the build progress. Once the build is complete, the pane disappears, and I’m left with a clean, organized workspace.

4. Custom Layouts

Zellij’s layout system lets you define complex multi-pane and multi-tab arrangements that can be reused across sessions. If you have a specific layout for different workflows—say, one for development and another for testing—you can switch between them seamlessly without having to reconfigure each time.

5. Intuitive Shortcuts

Zellij’s keyboard shortcuts are designed to be memorable and effective. Navigating between tabs, splitting panes, resizing them, or going full screen is straightforward. Here are a few that I find particularly useful:

  • Ctrl + t: Open a new tab.
  • Ctrl + p: Open a new pane.
  • Ctrl + Arrow Keys: Navigate between panes or tabs.
  • Ctrl + o + d: Detach from a session without closing it.

Zellij in Action: Building a Golang Project

Let’s walk through a scenario where I use Zellij to build a Golang project from scratch:

1. Start a Zellij Session

1
zellij --session golang-workspace

I start by opening a new session called golang-workspace and creating my default layout with three panes: one for writing code, one for running the build, and another for monitoring the test results.

2. Write the Code

In the first pane, I open my favorite editor and start writing a simple Golang application:

1
2
3
go mod init zellij-demo

nvim main.go

Inside main.go, I create a basic HTTP server:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, Zellij!")
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}

Now, let’s create a new file called main_test.go in the same directory to add a simple test for our handler function:

1
nvim main_test.go

Inside main_test.go, I add the following test code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

import (
    "net/http"
    "net/http/httptest"
    "testing"
)

// Test the handler function
func TestHandler(t *testing.T) {
    req, err := http.NewRequest("GET", "/", nil)
    if err != nil {
        t.Fatal(err)
    }

    rr := httptest.NewRecorder()
    handler(rr, req)

    expected := "Hello, Zellij!"
    if rr.Body.String() != expected {
        t.Errorf("handler returned unexpected body: got %v want %v", rr.Body.String(), expected)
    }
}

This simple test checks if the handler function returns the expected response when accessed via a GET request.

3. Run the Build Process in a Separate Pane

To open a new pane in Zellij, press:

1
2
3
4
5
Ctrl + p

# Then

n

This creates a new pane in the same session. Once the pane is open, I navigate to the project directory and build the application:

1
go build -o zellij-demo main.go

As soon as I execute the command, a floating pane appears to show the build status. Once the build is complete, the floating pane disappears, and the pane returns to its idle state.

4. Monitor Test Results

Similarly, I open another new pane using:

1
2
3
4
5
Ctrl + p

# Then

n

In this pane, I run a command to monitor test results:

1
go test -v ./...

5. Launch the Application

I switch back to the second pane (where I built the application) using:

1
2
3
Ctrl + p

Ctrl + Arrow Keys

Once in the correct pane, I launch the application:

1
./zellij-demo

The server is now running on localhost:8080, and I can verify it by opening a new tab in Zellij and using curl:

1
curl http://localhost:8080

With these three tasks running simultaneously, I can easily switch between them using Ctrl + Arrow Keys without losing my place or breaking my concentration.

  • Move to the next pane: Use Ctrl + Arrow Keys to switch between panes. Example: Ctrl + → moves to the pane on the right.
  • Move to the previous pane: Use Ctrl + ← to move back to the left pane.

This makes switching between your Golang code, build output, and test results seamless and fast.

Setting Up Your Perfect Zellij Configuration

Although I stick to the defaults for most of my work, Zellij is highly customizable. You can configure everything from key bindings to themes and layout definitions. Here’s a quick guide on how to create your own configuration file:

  1. Dump the Default Configuration:
1
zellij setup --dump-config > ~/.config/zellij/config.kdl
  1. Modify as Needed: Open the config.kdl file and tweak the settings to match your preferences. You can change key bindings, define new layouts, or even set a custom theme.

  2. Load the Configuration: Once your configuration is ready, load it in Zellij:

1
zellij --layout ~/.config/zellij/config.kdl

Why You Should Try Zellij Today!

After using Zellij for several months, I can say with confidence that it has improved my productivity significantly. Whether I’m building Golang applications, debugging a system, or running performance tests, Zellij allows me to work faster and more efficiently—all without touching the mouse. For anyone looking to streamline their terminal workflow, Zellij is a must-try.

If you’re a seasoned Tmux user, you’ll appreciate the polished experience that Zellij offers. And if you’re new to terminal multiplexers, Zellij’s user-friendly approach will make you a fan in no time.

Final Thoughts

Zellij is not just a tool; it’s a productivity booster that helps you stay organized and focused. With features like floating panes, session detachment, and intuitive shortcuts, it stands out as one of the best terminal multiplexers available today. Give it a try, and I’m sure you’ll find yourself wondering how you ever worked without it.

Zellij The future is terminal!

This post is licensed under CC BY 4.0 by the author.