Why Nushell?
We can do better than POSIX
I work on a command-line shell called Nushell (Nu for short) with some internet friends, and I think it’s pretty cool. To convince you that it’s cool (or at least worth a try), here’s a whirlwind tour.
Basic Querying
Let’s start by taking a look around the filesystem. We’ll use ls
to take a look at the files in /usr/bin
:
We got an actual table back! It has columns! 1551 rows is a bit much though; why don’t we see what the 10 biggest files are? We can use sort-by
to sort by size, and then grab the first 10 with first
:
Maybe we’re only interested in files that have been updated recently. Let’s add a where
to the pipeline to filter data:
And to cap it all off, let’s project the results; we’ll use select
to grab only the columns we care about:
- Sorting: maybe the command you’re using has sorting functionality built in, like
-S
in coreutilsls
. That’s the best case, and it involves remembering a bunch of different sorting flags for different commands. In the worst case, you’ll have to do string parsing to get a substring out of each line and then sort based on that. - Filtering: good luck! Filtering strings in simple ways with
grep
isn’t too bad. But if you’re working with more complex data types (like dates), you’ll have trouble. For example there isn’t a good way to filterls
output by date, and so most people give up onls
and usefind
instead. - Projecting: I hope you like string parsing. You’ll have to use
awk
or something similar to extract substrings from each line, and hope that your input data never changes in a way that causes things to break.
Working With Data
Nushell prides itself on making it easy to work with data from external sources — not just our built-in commands like ls
.
Say you have a TOML file. Reading it into a Nushell value is as simple as open foo.toml
, and once that’s done you can sort/filter/project it with exactly the same commands as we used with ls
above.
This isn’t limited to TOML; you can do the same with XML, JSON, CSV, Excel, and even SQLite. If the usual Nu commands work for your SQLite needs, great. If not, it’s easy to switch to SQL with query db
:
And if you want to bring in data from a web API, that’s easy too. Just run fetch <url>
, and JSON content will be automatically converted to a Nu table:
Cross-platform. Really.
Nu takes cross-platform support seriously. We develop and test against Linux, macOS, and Windows. This is a big selling point for me; other shells tend to support *nix well (bash, zsh) or Windows well (PowerShell) but not both.
What’s the catch?
It’s still (relatively) early days for Nu. We didn’t get everything right on the first try, there are still a few rough edges when it comes to command design. Accordingly, breaking changes can and do occur.
If you need a shell that will remain unchanged for decades to come, Nu is probably not right for you (yet). But if you’re willing to join us for a ride, you won’t be disappointed.