+++
title = "Nushell first impressions"
date = 2024-03-01T11:34:04-06:00
draft = true
+++
:caution-caption: pass:[<span style="font-size: 2em">☠</span>]
:important-caption: pass:[<span style="font-size: 2em">❗</span>]
:note-caption: pass:[<span style="font-size: 2em">✏️</span>]
:tip-caption: pass:[<span style="font-size: 2em">💡</span>]
:warning-caption: pass:[<span style="font-size: 2em">⚠</span>]
:toc:
:toclevels: 6

Ive been trying out a bunch of new shell utilites lately,
switching up my shell, terminal multiplexer, and even experimenting with my editor.
Today, Id like to focus on my experiments with my shell.

== My old setup

Before this, I had been using a minimal zsh setup for a long time,
with only built in features and a handmade prompt.
Zsh is a good shell, probably one of the best posix shells out there,
and I still use it when a posix shell is needed.

However, I got tired of the endless footguns that posix shell scripting imposes,
easy to make errors around quoting, word splitting, and escaping,
the sort of thing that makes https://www.shellcheck.net/[shellcheck] necessary.

I played around with fish for a few days,
but it had many of the same fundamental design choices, mainly, being 'stringly typed',
that made posix shells such a displeasure to work with.

== A Nu shell

While googling around for alternative shells, I stumbled across https://www.nushell.sh/[nushell],
a shell that claimed to work around structured data instead of just strings.
This was *exactly* what I was looking for, and I installed it immediately.
I decided to work with it for around a month,
give myself enough time to really use it,
see not only how it felt with ordinary usage,
but to give myself time and opportunity to construct a few pipelines and scripts in it.

All that said, the month is up, and ive been collecting examples,
thoughts, and some criticisms along the way.

== Piping structured data

// show some examples of grouping, sorting, etc without endless invocations of `cut`.

== Parsing non-nu tools

// show parsing initcall_debug logs, and how it then lets one do analysis on it
```
[    0.518096] calling  prandom_reseed+0x0/0x40 @ 1
[    0.518119] initcall prandom_reseed+0x0/0x40 returned 0 after 12 usecs
[    0.518127] calling  clk_debug_init+0x0/0x140 @ 1
[    0.531128] initcall clk_debug_init+0x0/0x140 returned 0 after 12659 usecs
[    0.531145] calling  imx_amp_power_init+0x0/0x13c @ 1
[    0.531156] initcall imx_amp_power_init+0x0/0x13c returned 0 after 1 usecs
[    0.531175] calling  deferred_probe_initcall+0x0/0x3c @ 1
[    0.532275] imx_thermal 2000000.aips-bus:tempmon: Automotive CPU temperature grade - max:125C critical:120C passive:115C
[    0.533166] pcm1753 pcm1753: Setting maximum volume limit of 226
[    0.535167] asoc-simple-card sound: PCM1753-HiFi <-> 2024000.esai mapping ok
[    0.536199] initcall deferred_probe_initcall+0x0/0x3c returned 0 after 4880 usecs
[    0.536217] calling  pm_genpd_debug_init+0x0/0x70 @ 1
[    0.536249] initcall pm_genpd_debug_init+0x0/0x70 returned 0 after 20 usecs
[    0.536262] calling  genpd_poweroff_unused+0x0/0x8c @ 1
[    0.536284] initcall genpd_poweroff_unused+0x0/0x8c returned 0 after 11 usecs
[    0.536296] calling  gpio_keys_init+0x0/0x20 @ 1
```

{{<highlight nushell "linenos=false">}}
open $file |
lines |
find '] initcall ' |
parse -r '\[\s*(?<timestamp>\d+\.\d+)\] (?<message>.+) returned (?<return>\d+) after (?<delta>.+)' |
update timestamp {into float} |
update delta {str replace ' usecs' 'us'} |
update delta {into duration} |
update return {into int} |
move delta --after timestamp
{{</highlight>}}

== Defining custom commands

// show the basic syntax for custom commands

=== Built in arg parsing?

// show syntax for custom args, and how it leads to auto completion and help generation.

== Error messages

== Whats not there yet

// explain some limitations, tools that assume the existence of a posix shell (esp files one is instructed to source)
// also explain the limitations where nushell scripts cannot pass structured data, but are treated as external commands, therefore their usefullness in a pipeline is limited.
