Photo - Kobi Li
Photo

Development


A Nu Shell

Finding some consistency on interacting with the machine.

Motivations

Cross Platform Consistency

Developing across multiple operating systems can be pretty annoying! Mac bash is different than Arch bash, which is different than Windows powershell. 😵‍💫

Mac defaults to zsh, but also packs an old bash (usually 3.2). Windows packs Powershell (usually 4, maybe 7), sometimes a msys or mingw or Git bash, and CMD.exe. Meanwhile Linux can pack... well, a lot of different things.

This means things like &> might work on some platforms, but not on others.

It also means things like cp, rm, and ls work consistently on nu. (Here's looking at rm -rf on Powershell, setting touch with timestamps on Mac vs Linux...)

Configuration

Installing

With a Rust toolchain:

cargo install nu

Without a Rust toolchain:

# Windows
winget install nu
# Mac
brew install nu
# Arch Linux
pacman -S nu

Working with it

Coming from Bash is quite helpful.

nu works slightly differently than other shells in that it separates parsing and evaluation. More in How Nushell Code Gets Run.

Piping to Files

nu doesn't have a > pipe. Instead:

cat floof | save boop

For >>:

cat floof | save -a boop

Loops

Loops differ syntactically from bash in several ways.

For example, unpacking all the archives in the parent directory into the current directory:

for archive in (ls .. | where type != dir) { tar xvf $archive.name }

Similar, but unarchiving into named directories:

for archive in (ls | where type != dir) {
    let archive_stem = $archive.name | path parse | get stem
    mkdir $archive_stem
    cd $archive_stem
    let archive_path = ".." | path join $archive.name
    tar xvf $archive_path
    cd ..
}

Parameter Expansion

Different shells approach parameter expansion differently.

In bash we can do like:

./x.py --stage 2 dist $(ferrocene/ci/split-tasks.py dist)

While fish it looks like:

./x.py --stage 2 dist $(ferrocene/ci/split-tasks.py dist | string split " ")

On nu we do this:

./x.py --stage 2 dist ...(python ferrocene/ci/split-tasks.py dist | split row " ")

Environments

Notes on using a variety of environments I immerse myself in.


Rust at Scale

Shipping safe, fast, and fun.

1867cdb4648edf7344e3233c665e62da7410a020