9

Zellij 0.32.0: YAML => KDL, Control Zellij through the CLI, Command Panes and...

 1 year ago
source link: https://zellij.dev/news/config-command-layouts/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Zellij 0.32.0: YAML => KDL, Control Zellij through the CLI, Command Panes and a new Layout System

2022-10-25 :: Aram Drevekenin

We just release Zellij 0.32.0 with lots of exciting features and improvements.

In this version, we emphasized features geared toward advanced users. We feel Zellij already provides a great experience to users new to terminal multiplexers, and would now like to make configuring and personalizing the tool easier. We want to grant power users the ability to better harness their terminal workspace, expressing their imagination and sharing their findings with the community.

You can go right ahead and install it or read on for more details.

YAML => KDL

kdl file preview

This coming version moves all of the Zellij configuration from YAML to KDL.

Existing configuration and layout files will be automatically converted, with the originals unmodified. The conversion can also be done manually.

Read more about the new configuration here.

Curious how we chose KDL? Read about it below

Command Panes

This release introduces Command Panes. These are terminal panes that run a specific command. When the command exits, they stay open, allowing the user to:

  • See the Exit Code
  • Re-run the command with ENTER
  • Close the pane with Ctrl-c

These panes can be moved, resized, de-focused, floated or embedded like any other terminal pane.

We believe this is a powerful new way to interact with the terminal.

Command panes play a role in both the layout system and as shown above in Zellij Run.

Control Zellij through the CLI

A long requested feature of Zellij has been the ability to script it and generally control the tool through the command-line.

This release introduces this ability fully in Zellij Actions as well as providing top-level conveniences in Zellij Run and Zellij Edit.

Zellij Run

# Out of the box
$ zellij run -- git diff

# With a convenient alias for your shell
$ zr git diff

Zellij run lets users run a new command from the command line in a Command Pane.

For more information and options see the Zellij Run documentation.

For the alias, see Zellij CLI completions.

Zellij Edit

# Out of the box
$ zellij edit my-file.rs

# With a convenient alias for your shell
$ ze my-file.rs

Zellij edit lets users open a new pane with their default editor (eg. vim) pointed at the provided file.

For more information see the Zellij Edit documentation.

For the alias, see Zellij CLI completions.

Zellij Action

$ zellij action switch-mode locked

$ zellij action rename-pane TESTS

Zellij action is the CLI entry-point for Zellij. It provides an extensive list of actions that can be performed on the current or other sessions.

Anything from locking the interface to opening a new tab with a specified layout.

For more information, see Controlling Zellij through the CLI.

New Layout System

While converting our old layout system to use KDL, we decided to both simplify it and make it more powerful.

We would like Zellij layouts to be part of a command-line user’s toolbox. Allowing them to be used as quick shortcuts to dynamically open a predefined set of panes with commands and CWDs, defined and adjusted on the fly and shared in dotfile repositories.

The new layout system also includes entirely new capabilities such as pane_templates, tab_templates and cwd composition to allow for more dynamic layouts.

Example Layout

layout {
    pane split_direction="vertical" size="60%" {
        pane edit="src/main.rs"
        pane edit="Cargo.toml"
    }
    pane split_direction="vertical" size="40%" {
        pane command="cargo" {
            args "run"
            focus true
        }
        pane command="cargo" {
            args "test"
        }
    }
}

Opening this layout in a new-tab in a Rust boilerplate project can look like this:

$ zellij action new-tab --layout /path/to/above/layout-file.kdl
basic-rust-project-layout-example

See more examples or read more about layouts.

Did you make a cool and/or useful Zellij layout? Please tweet it at us or post it in our Reddit.

What else?

Throughout October, Zellij participated in Hacktoberfest. We emphasized contributions to improve our Error Handling story, contributing both to the stability of Zellij and to better communicating error causes and remedies to users.

We heartily thank all of our community contributors.

What’s next for Zellij?

In the coming months, we’re going to overhaul Zellij’s plugin system. We have unfortunately not been able to devote to it the attention it deserves ever since Zellij has been released due to maintainer availability. This will soon change. Look out for more info on it in the near future.

Addendum: Why did we choose KDL?

Why not YAML?

Much has been said about the downsides of YAML, for us it boiled down to:

  1. Indentation being meaningful - configuration files, and especially layouts can get very large. Changing an arbitrary part in the middle of 100s or 1000s of lines becomes a challenge and often, in the context of build-systems and production use, a source of anxiety. We want our users to love using our configuration language, not fear it.
  2. Copying and Pasting parts from other sources can be disastrous - The Zellij configuration and layout system benefits from re-use and tricks learned from the community. These snippets, when copy/pasted, can do unexpected things in different contexts depending on their indentation amount or even type.

Why KDL?

When looking at configuration languages, we ended up considering either TOML or KDL. The former, while being excellent and fairly popular, doesn’t make nesting very easy. Since our layouts make heavy use of nesting, this was a deal-breaker for us.

While working with KDL, we found its easy-to-pick-up syntax pleasant both to write and to read - even when dealing with large files. And while there are downsides, the great ecosystem around KDL for Rust allowed us to incorporate some really helpful and verbose errors to help guide users in creating configuration and layout files.

kdl error demo

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK