๐Ÿ’พ Archived View for perso.pw โ€บ blog โ€บ articles โ€บ nushell.gmi captured on 2024-07-09 at 00:16:59. Gemini links have been rewritten to link to archived content

View Raw

More Information

โฌ…๏ธ Previous capture (2023-11-04)

-=-=-=-=-=-=-

Nushell: Introduction to a new kind of shell

Comment on Mastodon

What is nushell

Let me introduce you to a nice project I found while lurking on the Internet. It's called nushell and is a non-POSIX shell, so most of your regular shells knowledge (zsh, bash, ksh, etcโ€ฆ) can't be applied on it, and using it feels like doing functional programming.

It's a good tool for creating robust data manipulation pipelines, you can think of it like a mix of a shell which would include awk's power, behave like a SQL database, and which knows how to import/export XML/JSON/YAML/TOML natively.

You may want to try nushell only as a tool, and not as your main shell, it's perfectly fine.

With a regular shell, iterating over a command output can be complex when it involves spaces or newlines, for instance, that's why `find` and `xargs` have a `-print0` parameter to have a special delimited between "items", but it doesn't compose well with other tools. Nushell handles correctly this situation as its manipulates the data using indexed entries, given you correctly parsed the input at the beginning.

Nushell official project page

Nushell documentation website

How to get it

Nushell is a rust program, so it should work on every platform where Rust/Cargo are supported. I packaged it for OpenBSD, so it's available on -current (and will be in releases after 7.3 is out), the port could be used on 7.2 with no effort.

With Nix, it's packaged under the name `nushell`, the binary name is `nu`.

For other platforms, it's certainly already packaged, otherwise you can find installation instructions to build it from sources.

Nushell documentation: Building nushell from sources

Configuration

At first run, you are prompted to use default configuration files, I'd recommend accepting, you will have files created in `~/.config/nushell/`.

The only change I made from now is to make Tab completion case-sensitive, so `D[TAB]` completes to `Downloads` instead of asking between `dev` and `Downloads`. Look for `case_sensitive_completions` in `.config/nushell/config.nu` and set it to `true`.

Examples

If you are like me, and you prefer learning by doing instead of reading a lot of documentation, I prepared a bunch of real world use case you can experiment with. The documentation is still required to learn the many commands and syntax, but examples are a nice introduction.

Getting help

Help from nushell can be parsed directly with nu commands, it's important to understand where to find information about commands.

Use `help a-command` to learn from a single command:

> help help
Display help information about commands.

Usage:
  > help {flags} ...(rest) 

Flags:
  -h, --help - Display this help message
  -f, --find <String> - string to find in command names, usage, and search terms

[cut so it's not too long]

Use `help commands` to list all available commands (I'm limiting to 5 between there are a lot of commands)

help commands | last 5
โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ # โ”‚    name     โ”‚        category        โ”‚ is_plugin โ”‚ is_custom โ”‚ is_keyword โ”‚                                         usage                                         โ”‚ search_terms โ”‚
โ”œโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 0 โ”‚ window      โ”‚ filters                โ”‚ false     โ”‚ false     โ”‚ false      โ”‚ Creates a sliding window of `window_size` that slide by n rows/elements across input. โ”‚              โ”‚
โ”‚ 1 โ”‚ with-column โ”‚ dataframe or lazyframe โ”‚ false     โ”‚ false     โ”‚ false      โ”‚ Adds a series to the dataframe                                                        โ”‚              โ”‚
โ”‚ 2 โ”‚ with-env    โ”‚ env                    โ”‚ false     โ”‚ false     โ”‚ false      โ”‚ Runs a block with an environment variable set.                                        โ”‚              โ”‚
โ”‚ 3 โ”‚ wrap        โ”‚ filters                โ”‚ false     โ”‚ false     โ”‚ false      โ”‚ Wrap the value into a column.                                                         โ”‚              โ”‚
โ”‚ 4 โ”‚ zip         โ”‚ filters                โ”‚ false     โ”‚ false     โ”‚ false      โ”‚ Combine a stream with the input                                                       โ”‚              โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Add `sort-by category` to list them... sorted by category.

help commands | sort-by category

Use `where category == filters` to only list commands from the `filters` category.

help commands | where category == filters

Use `find foobar` to return lines containing `foobar`.

help commands | find insert

General examples

Converting a data structure into another

This is just an example from YAML to JSON, but you can convert much more formats into other formats.

open dev/home-impermanence/tests/impermanence.yml | to json
{
  "directories":
  [
    "Documents",
    "Downloads",
    "Datastore/Music",
    "Datastore",
    "Datastore/",
    "Datastore/Music/Band1",
    ".config",
    "foo/bar",
    "foo/bar/hello"
  ],
  "size": "500m",
  "files":
  [
    ".Xdefaults",
    ".profile",
    ".xsession",
  ]
}

Parsing sysctl output

sysctl -a | parse -r "(?<key>.*?)=(?<value>.*)"

Because the output would be too long, here is how you get 10 random keys from sysctl.

sysctl -a | parse -r "(?<key>.*?)=(?<value>.*)" | shuffle | last 10 | sort-by key
โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ # โ”‚                       key                       โ”‚  value   โ”‚
โ”œโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 0 โ”‚ fs.quota.reads                                  โ”‚  0       โ”‚
โ”‚ 1 โ”‚ net.core.high_order_alloc_disable               โ”‚  0       โ”‚
โ”‚ 2 โ”‚ net.ipv4.conf.all.drop_gratuitous_arp           โ”‚  0       โ”‚
โ”‚ 3 โ”‚ net.ipv4.conf.default.rp_filter                 โ”‚  2       โ”‚
โ”‚ 4 โ”‚ net.ipv4.conf.lo.disable_xfrm                   โ”‚  1       โ”‚
โ”‚ 5 โ”‚ net.ipv4.conf.lo.forwarding                     โ”‚  0       โ”‚
โ”‚ 6 โ”‚ net.ipv4.ipfrag_low_thresh                      โ”‚  3145728 โ”‚
โ”‚ 7 โ”‚ net.ipv6.conf.all.ioam6_id                      โ”‚  65535   โ”‚
โ”‚ 8 โ”‚ net.ipv6.conf.all.router_solicitation_interval  โ”‚  4       โ”‚
โ”‚ 9 โ”‚ net.mptcp.enabled                               โ”‚  1       โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Recursively convert FLAC files to OPUS

A complicated task using a regular shell, recursively find files matching a pattern and then run a given command on each of them, in parallel. Which is exactly what you need if you want to convert your music library into another format, let's convert everything from FLAC to OPUS in this example.

In the following command line, we will look for every `.flac` file in the subdirectories, then run in parallel using `par-each` the command `ffmpeg` on it, from its current name to the old name with `.flac` changed to `.opus`.

The `let convert` and `| complete` commands are used to store the output of each command into a result table, and store it in the variable `convert` so we can query it after the job is done.

let convert = (ls **/*flac | par-each { |file| do -i { ffmpeg -i $file.name ($file.name | str replace flac opus) } | complete })

Now, we have a structure in `convert` that contains the columns `stdout`, `stderr` and `exit_code`, so we can look if all the commands did run correctly using the following query.

$convert | where exit_code != 0

Synchronize a music library to a compressed one

I had a special need for my phone and my huge music library, I wanted to have a lower quality version of it synced with syncthing, but I needed this to be easy to update when adding new files.

It takes all the music files in `/home/user/Music/` and creates a 64K opus file in `/home/user/Stream/` by keeping the same file tree hierarchy, and if the opus destination file exists it's skipped.

cd /home/user/Music/
let dest = "/home/user/Stream/"
let convert = (ls **/* |
			where name =~ ".(mp3|flac|opus|ogg)$" | 
			where name !~ "(Audiobook|Piano)" | 
			par-each {
				|file| do -i {
					let new_name = ($file.name | str replace -r ".(flac|ogg|mp3)" ".opus")
					if (not ([$dest, $new_name] | str join | path exists)) {
						mkdir ([$dest, ($file.name | path dirname)] | str join)
						ffmpeg -i $file.name -b:a 64K ([$dest, $new_name] | str join)
					} | complete
				}
			})
$convert

Convert PDF/CBR/CBZ pages into webp and CBZ archives

I have a lot of digitalized books/mangas/comics, this conversion is a handy operation reducing the size of the files by 40% (up to 70%).

def conv [] {
	if (ls | first | get name | str contains ".jpg") {
	  ls *jpg | par-each {|file| do -i { cwebp $file.name -o ($file.name | str replace jpg webp) } | complete }
          rm *jpg
	}
	if (ls | first | get name | str contains ".ppm") {
	  ls *ppm | par-each {|file| do -i { cwebp $file.name -o ($file.name | str replace ppm webp) } | complete }
	  rm *ppm
	}
}
ls * | each {|file| do -i {
	if ($file.name | str contains ".cbz") { unzip $file.name -d ./pages/ } ;
	if ($file.name | str contains ".cbr") { unrar e -op./pages/ $file.name } ;
        if ($file.name | str contains ".pdf") { mkdir pages ; pdfimages $file.name pages/page } ;
	cd pages ; conv ; cd ../ ; ^zip -r $"($file.name).webp.cbz" pages ; rm -fr pages
} }

Parse gnu tar output

ใ€‰tar vtf nushell.tgz  | parse -r "(.*?) (.*?)\/(.*?)\\s+(.*?) (.*?) (.*?) (.*)" | rename mode owner group size date time path
โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ # โ”‚    mode    โ”‚ owner  โ”‚ group โ”‚ size  โ”‚    date    โ”‚ time  โ”‚        path        โ”‚
โ”œโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 0 โ”‚ drwxr-xr-x โ”‚ solene โ”‚ wheel โ”‚ 0     โ”‚ 2022-10-30 โ”‚ 16:45 โ”‚ nushell            โ”‚
โ”‚ 1 โ”‚ -rw-r--r-- โ”‚ solene โ”‚ wheel โ”‚ 519   โ”‚ 2022-10-30 โ”‚ 13:41 โ”‚ nushell/Makefile   โ”‚
โ”‚ 2 โ”‚ -rw-r--r-- โ”‚ solene โ”‚ wheel โ”‚ 29304 โ”‚ 2022-10-29 โ”‚ 18:49 โ”‚ nushell/crates.inc โ”‚
โ”‚ 3 โ”‚ -rw-r--r-- โ”‚ solene โ”‚ wheel โ”‚ 75003 โ”‚ 2022-10-29 โ”‚ 13:16 โ”‚ nushell/distinfo   โ”‚
โ”‚ 4 โ”‚ drwxr-xr-x โ”‚ solene โ”‚ wheel โ”‚ 0     โ”‚ 2022-10-30 โ”‚ 00:00 โ”‚ nushell/pkg        โ”‚
โ”‚ 5 โ”‚ -rw-r--r-- โ”‚ solene โ”‚ wheel โ”‚ 337   โ”‚ 2022-10-29 โ”‚ 18:52 โ”‚ nushell/pkg/DESCR  โ”‚
โ”‚ 6 โ”‚ -rw-r--r-- โ”‚ solene โ”‚ wheel โ”‚ 14    โ”‚ 2022-10-29 โ”‚ 18:53 โ”‚ nushell/pkg/PLIST  โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Opening spreadsheets

ใ€‰open --raw freq.ods | from ods | get Sheet1 | headers
โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ # โ”‚   Policy    โ”‚ Compile time โ”‚ Idle time โ”‚ column3 โ”‚ Compile power โ”‚ Idle power โ”‚ Total โ”‚ column8 โ”‚ column9 โ”‚ column10 โ”‚
โ”œโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 0 โ”‚ powersaving โ”‚      1123.00 โ”‚      0.00 โ”‚         โ”‚          5.90 โ”‚       0.00 โ”‚  5.90 โ”‚         โ”‚         โ”‚          โ”‚
โ”‚ 1 โ”‚ auto        โ”‚       871.00 โ”‚    252.00 โ”‚         โ”‚          5.60 โ”‚       0.74 โ”‚  6.34 โ”‚         โ”‚    0.44 โ”‚     6.94 โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

We can format new strings from columns values.

ใ€‰open --raw freq.ods | from ods | get Sheet1 | headers | each {|row| do { echo $"($row.Policy) = ($row.'Compile power' + $row.'Idle power') Watts" } }
โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ 0 โ”‚ powersaving = 5.9 Watts โ”‚
โ”‚ 1 โ”‚ auto = 6.34 Watts       โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Filter and sort a JSON

There is a website listing packages that can be updated on OpenBSD at https://portroach.openbsd.org, it provides json of data for rendering.

We can use this data to sort which maintainer has the most up to date percentage, but only if they manage more than 30 packages.

fetch https://portroach.openbsd.org/json/totals.json | get results | where total > 30 | sort-by percentage

NixOS examples

Query profiles packages

nix profile list | parse "{index} {flake} {source} {store}"
โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€๏ฟฝ๏ฟฝโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ # โ”‚                         flake                         โ”‚                                      source                                      โ”‚                              store                              โ”‚
โ”œโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 0 โ”‚ flake:nixpkgs#legacyPackages.x86_64-linux.libreoffice โ”‚ path:/nix/store/iw3xi0bfszikb0dmyywp7pm590jvbqvs-source?lastModified=1663494472& โ”‚ /nix/store/1m6wp1pznhf2nrvs7xwmvig5x3nspq0j-libreoffice-7.2.6.2 โ”‚
โ”‚   โ”‚                                                       โ”‚ narHash=sha256-fSowlaoXXWcAM8m9wA6u+eTJJtvruYHMA+Lb%2ftFi%2fqM=&rev=f677051b8dc0 โ”‚                                                                 โ”‚
โ”‚   โ”‚                                                       โ”‚ b5e2a9348941c99eea8c4b0ff28f#legacyPackages.x86_64-linux.libreoffice             โ”‚                                                                 โ”‚
โ”‚ 1 โ”‚ flake:nixpkgs#legacyPackages.x86_64-linux.dino        โ”‚ path:/nix/store/9cj1830pvd88lrwmmxw65achd3lw2q9n-source?lastModified=1667050928& โ”‚ /nix/store/ljhn4n1q5pk7wr337v681m1h39jp5l2y-dino-0.3.0          โ”‚
โ”‚   โ”‚                                                       โ”‚ narHash=sha256-xOn0ZgjImIyeecEsrjxuvlW7IW5genTwvvnDQRFncB8=&rev=fdebb81f45a1ba2c โ”‚                                                                 โ”‚
โ”‚   โ”‚                                                       โ”‚ 4afca5fd9f526e1653ad0949#legacyPackages.x86_64-linux.dino                        โ”‚                                                                 โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Query flakes

nix flake show --json | from json
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ defaultPackage โ”‚ {record 5 fields} โ”‚
โ”‚ packages       โ”‚ {record 5 fields} โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

nix flake show --json | from json | get packages
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ aarch64-darwin โ”‚ {record 2 fields} โ”‚
โ”‚ aarch64-linux  โ”‚ {record 2 fields} โ”‚
โ”‚ i686-linux     โ”‚ {record 2 fields} โ”‚
โ”‚ x86_64-darwin  โ”‚ {record 2 fields} โ”‚
โ”‚ x86_64-linux   โ”‚ {record 2 fields} โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

nix flake show --json | from json | get packages.x86_64-linux
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ nix-dev-html  โ”‚ {record 2 fields} โ”‚
โ”‚ nix-dev-pyenv โ”‚ {record 3 fields} โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Parse a flake.lock file

> open flake.lock | from json | get nodes.nixpkgs.locked
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ lastModified โ”‚ 1663494472                                          โ”‚
โ”‚ narHash      โ”‚ sha256-fSowlaoXXWcAM8m9wA6u+eTJJtvruYHMA+Lb/tFi/qM= โ”‚
โ”‚ path         โ”‚ /nix/store/iw3xi0bfszikb0dmyywp7pm590jvbqvs-source  โ”‚
โ”‚ rev          โ”‚ f677051b8dc0b5e2a9348941c99eea8c4b0ff28f            โ”‚
โ”‚ type         โ”‚ path                                                โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

OpenBSD examples

Parse /etc/fstab

> open /etc/fstab | from ssv -m 1 -n | rename device mountpoint fs options freq passno
_โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€_
โ”‚  # โ”‚       device       โ”‚   mountpoint    โ”‚  fs  โ”‚                  options                  โ”‚ freq โ”‚ passno โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  0 โ”‚ 55a6c21017f858cb.b โ”‚ none            โ”‚ swap โ”‚ sw                                        โ”‚ __   โ”‚ __     โ”‚
โ”‚  1 โ”‚ 55a6c21017f858cb.a โ”‚ /               โ”‚ ffs  โ”‚ rw,noatime,softdep                        โ”‚ 1    โ”‚ 1      โ”‚
โ”‚  2 โ”‚ 55a6c21017f858cb.l โ”‚ /home           โ”‚ ffs  โ”‚ rw,noatime,wxallowed,softdep,nodev,nosuid โ”‚ 1    โ”‚ 2      โ”‚
โ”‚  3 โ”‚ 55a6c21017f858cb.d โ”‚ /tmp            โ”‚ ffs  โ”‚ rw,noatime,softdep,nodev,nosuid           โ”‚ 1    โ”‚ 2      โ”‚
โ”‚  4 โ”‚ 55a6c21017f858cb.f โ”‚ /usr            โ”‚ ffs  โ”‚ rw,noatime,softdep,nodev                  โ”‚ 1    โ”‚ 2      โ”‚
โ”‚  5 โ”‚ 55a6c21017f858cb.g โ”‚ /usr/X11R6      โ”‚ ffs  โ”‚ rw,noatime,softdep,nodev                  โ”‚ 1    โ”‚ 2      โ”‚
โ”‚  6 โ”‚ 55a6c21017f858cb.h โ”‚ /usr/local      โ”‚ ffs  โ”‚ rw,noatime,softdep,wxallowed,nodev        โ”‚ 1    โ”‚ 2      โ”‚
โ”‚  7 โ”‚ 55a6c21017f858cb.k โ”‚ /usr/obj        โ”‚ ffs  โ”‚ rw,noatime,softdep,nodev,nosuid           โ”‚ 1    โ”‚ 2      โ”‚
โ”‚  8 โ”‚ 55a6c21017f858cb.j โ”‚ /usr/src        โ”‚ ffs  โ”‚ rw,noatime,softdep,nodev,nosuid           โ”‚ 1    โ”‚ 2      โ”‚
โ”‚  9 โ”‚ 55a6c21017f858cb.e โ”‚ /var            โ”‚ ffs  โ”‚ rw,noatime,softdep,nodev,nosuid           โ”‚ 1    โ”‚ 2      โ”‚
โ”‚ 10 โ”‚ afebb2a83a449265.b โ”‚ /build          โ”‚ ffs  โ”‚ rw,noatime,softdep,wxallowed,nosuid       โ”‚ 1    โ”‚ 2      โ”‚
โ”‚ 11 โ”‚ afebb2a83a449265.a โ”‚ /build/pobj     โ”‚ ffs  โ”‚ rw,noatime,softdep,nodev,wxallowed,nosuid โ”‚ 1    โ”‚ 2      โ”‚
โ”‚ 12 โ”‚ 55a6c21017f858cb.b โ”‚ /build/pobj_mfs โ”‚ mfs  โ”‚ -s1G,wxallowed,noatime,rw                 โ”‚ 0    โ”‚ 0      โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€_

Parse /var/log/messages

open /var/log/messages | parse -r "(?<date>\\w+ \\d+ \\d+:\\d+:\\d+) (?<hostname>\\w+) (?<program>\\w+)\\[?(?<pid>\\d+)?\\]?: (?<message>.*)"
โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ # โ”‚      date       โ”‚ hostname โ”‚  program   โ”‚  pid  โ”‚                                                             message                                                             โ”‚
โ”œโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 0 โ”‚ Oct 31 10:27:32 โ”‚ fx6      โ”‚ collectd   โ”‚ 55258 โ”‚ uc_update: Value too old: name = fx6openbsd/swap/swap-free; value time = 1667208452.108; last cache update = 1667208452.108;    โ”‚
โ”‚ 1 โ”‚ Oct 31 10:43:02 โ”‚ fx6      โ”‚ collectd   โ”‚ 55258 โ”‚ uc_update: Value too old: name = fx6openbsd/swap/percent-free; value time = 1667209382.102; last cache update = 1667209382.102; โ”‚
โ”‚ 2 โ”‚ Oct 31 11:00:01 โ”‚ fx6      โ”‚ syslogd    โ”‚ 4629  โ”‚ restart                                                                                                                         โ”‚
โ”‚ 3 โ”‚ Oct 31 11:05:26 โ”‚ fx6      โ”‚ pkg_delete โ”‚       โ”‚ Removed helix-22.08.1                                                                                                           โ”‚
โ”‚ 4 โ”‚ Oct 31 11:05:29 โ”‚ fx6      โ”‚ pkg_add    โ”‚       โ”‚ Added helix-22.08.1                                                                                                             โ”‚
โ”‚ 5 โ”‚ Oct 31 11:16:49 โ”‚ fx6      โ”‚ pkg_add    โ”‚       โ”‚ Added llvm-13.0.0p3                                                                                                             โ”‚
โ”‚ 6 โ”‚ Oct 31 11:20:18 โ”‚ fx6      โ”‚ pkg_add    โ”‚       โ”‚ Added clang-tools-extra-13.0.0p2                                                                                                โ”‚
โ”‚ 7 โ”‚ Oct 31 11:20:32 โ”‚ fx6      โ”‚ pkg_add    โ”‚       โ”‚ Added bash-5.2.2                                                                                                                โ”‚
โ”‚ 8 โ”‚ Oct 31 11:20:34 โ”‚ fx6      โ”‚ pkg_add    โ”‚       โ”‚ Added fzf-0.34.0                                                                                                                โ”‚
โ”‚ 9 โ”‚ Oct 31 11:21:01 โ”‚ fx6      โ”‚ pkg_delete โ”‚       โ”‚ Removed fzf-0.34.0                                                                                                              โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Parse pkg_info output

pkg_info | str trim |  parse -r "(?<package>.*?)-(?<version>[a-zA-Z0-9\\.]*?) (?<description>.*)"  | str trim description
โ•ญโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  # โ”‚      package      โ”‚  version   โ”‚                    description                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  0 โ”‚ athn-firmware     โ”‚ 1.1p4      โ”‚ firmware binary images for athn(4) driver          โ”‚
โ”‚  1 โ”‚ collectd          โ”‚ 5.12.0     โ”‚ system metrics collection engine                   โ”‚
โ”‚  2 โ”‚ curl              โ”‚ 7.85.0     โ”‚ transfer files with FTP, HTTP, HTTPS, etc.         โ”‚
โ”‚  3 โ”‚ gettext-runtime   โ”‚ 0.21p1     โ”‚ GNU gettext runtime libraries and programs         โ”‚
โ”‚  4 โ”‚ intel-firmware    โ”‚ 20220809v0 โ”‚ microcode update binaries for Intel CPUs           โ”‚
โ”‚  5 โ”‚ inteldrm-firmware โ”‚ 20220913   โ”‚ firmware binary images for inteldrm(4) driver      โ”‚
โ”‚  6 โ”‚ kakoune           โ”‚ 2021.11.08 โ”‚ modal code editor with a focus on interactivity    โ”‚
โ”‚  7 โ”‚ libgcrypt         โ”‚ 1.10.1p0   โ”‚ crypto library based on code used in GnuPG         โ”‚
โ”‚  8 โ”‚ libgpg-error      โ”‚ 1.46       โ”‚ error codes for GnuPG related software             โ”‚
โ”‚  9 โ”‚ libiconv          โ”‚ 1.17       โ”‚ character set conversion library                   โ”‚
โ”‚ 10 โ”‚ libstatgrab       โ”‚ 0.91p5     โ”‚ system statistics gathering library                โ”‚
โ”‚ 11 โ”‚ libxml            โ”‚ 2.10.3     โ”‚ XML parsing library                                โ”‚
โ”‚ 12 โ”‚ libyajl           โ”‚ 2.1.0      โ”‚ small JSON library written in ANSI C               โ”‚
โ”‚ 13 โ”‚ nghttp2           โ”‚ 1.50.0     โ”‚ library for HTTP/2                                 โ”‚
โ”‚ 14 โ”‚ nushell           โ”‚ 0.70.0     โ”‚ a new kind of shell                                โ”‚
โ”‚ 15 โ”‚ obsdfreqd         โ”‚ 1.0.3      โ”‚ userland daemon to manage CPU frequency            โ”‚
โ”‚ 16 โ”‚ quirks            โ”‚ 6.42       โ”‚ exceptions to pkg_add rules and cache              โ”‚
โ”‚ 17 โ”‚ rsync             โ”‚ 3.2.5pl0   โ”‚ mirroring/synchronization over low bandwidth links โ”‚
โ”‚ 18 โ”‚ ttyplot           โ”‚ 1.4p0      โ”‚ realtime plotting utility for terminals            โ”‚
โ”‚ 19 โ”‚ vmm-firmware      โ”‚ 1.14.0p0   โ”‚ firmware binary images for vmm(4) driver           โ”‚
โ”‚ 20 โ”‚ xz                โ”‚ 5.2.7      โ”‚ LZMA compression and decompression tools           โ”‚
โ”‚ 21 โ”‚ yash              โ”‚ 2.52       โ”‚ POSIX-compliant command line shell                 โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Conclusion

Nushell is very fun, it's terribly different from regular shells, but it comes with a powerful language and tooling. I always liked shells because of pipes commands, allowing to construct a complex transformation/analysis step by step, and easily inspect any step, or be able to replace a step by another.

With nushell, it feels like I finally have a better tool to create more reliable, robust, portable and faster command pipelines. The learning curve didn't feel too hard, but maybe it's because I'm already used to functional programming.