Nu Shell

Most of us think the set of terminal environments that are included in most distributions are perennial. They're always there, they seem to have always been there, and they seldom change. People will stick with their chosen environment for decades, perhaps only switching between a distro's default Bash for something more ambitious (such as Zsh) when their needs change. However, all of this doesn't mean there shouldn't be new terminal environments, especially as the computing landscape is completely different from when Bash or Zsh were created. Microsoft's PowerShell has become very popular, for example, especially on a Windows environment when dealing with platforms like .NET and Azure. And Nu Shell attempts to do the same thing for Linux. It's a new shell environment built around the old Unix philosophy of simple commands connected together, built using the modern Rust programming language to better work with a new generation of terminal users, and built to take advantage of data.

As it's built using Rust, Nu can be easily installed via Rust's cargo package manager, which means it has great multiplatform support. With it installed, the first thing you're likely to do without even thinking about it is run ls, and this is where the Nu's differences first become apparent. Rather than returning the simple file list you might be expecting, the results from ls are returned in a formatted ASCII table, with separate columns for name, type, and size. This table output is the default for many of the built-in commands, including date, ps, and sys. It's this structuring of data that makes Nu different from other shells. Nu Shell can parse this data as either simple types like integers, booleans, paths, and string, or more structured types, such as a table row, a binary file, lists, and even chunks of code. You can see this in action with the open command, which is a viewer for various data formats. A YAML file is shown as a table, for instance, whereas a text file is simply displayed. Similarly, if Nu understands what constitutes a field within a file, or a field that has been delimited with a known character, those fields can be processed just as you might a single element of output.

To help with this data processing, Nu also includes an expanded pipeline. This works in three parts: an input, a filter, and the output. The excellent documentation includes an example that takes a TOML file as input and uses the filter to search and increment a version field before saving the output to a new file. There's also some great use of color. Command colors are different from argument colors, which are different from the values you may pass to a command. Pipes are colored differently too, and while the colors themselves will depend on your terminal's configuration, this differentiation makes commands easier to understand and helps you avoid mistakes. All of this is bound together with an intuitive autocomplete that helps you deal with the new syntax. It takes some time to learn, but Nu Shell is a great tool if you often find yourself constructing long lines in Bash to deal with esoteric output.

The main difference between Nu Shell and something like Bash is that output has a context that is passed to other commands, such as sorting the output of ls by size.
Accessing fields in command output and known file formats is much like querying a database, only your computer and its data are the dataset.

Project Website

Vim trainer


Vim, the terminal-based text editor, has been around for a long time, but in all this time, its steep learning curve has never been associated with entertainment. PacVim almost manages to do this by turning Vim navigation keys into a challenging Pacman-like game that also happens to teach you how to navigate in the venerable editor. The whole game uses Curses to render each level into the terminal using characters, with bars and pipes for the tunnels and alphanumeric characters formed into words as their background. At first glance, these seem like little more than background decoration, but of course, they're not. You're supposed to use Vim's comprehensive word and character navigation keys to move as quickly as you can through the maze because your mission is to turn them all green while avoiding the red Gs that act as ghosts chasing you.

It's actually difficult to get started, because the game doesn't hold your hand or tell you how you might best approach each level. Much like the arcade game, you need to try different strategies while you slowly get better. Even though the game starts with only two ghosts chasing you, it's still hard. They move in real time, which means there's no pause when you don't press a key. You also have to avoid tilde symbols and the edge of the maze, as these will take one of your lives away, and the corridors themselves are often multiple characters wide, which means you need to move through every character. The only way to really beat the game is to master the Vim keys that move you through words and up columns quickly, which if you can master this means you've also mastered Vim.

Alongside Vim's normal up, down, left, and right, you can also use commands like w, E, $, and gg to navigate the maze.

Project Website

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95