Skip to content

Instantly share code, notes, and snippets.

@lambda-mike
Last active February 9, 2024 16:10
Show Gist options
  • Save lambda-mike/e5aa3b73d05f56ccb4b2f8a2d2366817 to your computer and use it in GitHub Desktop.
Save lambda-mike/e5aa3b73d05f56ccb4b2f8a2d2366817 to your computer and use it in GitHub Desktop.
Nu shell cheatsheet

Nu shell

https://www.nushell.sh/about.html

help

Config

config --set [env $nu.env]

config --set [path $nu.path]

config | get env | pivot

Navigation

shells - list shells

n p - next/prev

enter - create new shell

exit - kill shell (remove from the ring buffer)

exit --now - kill all shells immediately and exit

Cmds

ls -f | where type == Dir - -f for printing all available info

ps | where name == node | format "{pid}" | kill -9 $it

sys | get mem | to json | clip - clip puts stuff to the copy/paste buffer

cargo search shells --limit 10 | lines | parse "{crate_name} = {version} #{description}" - parsing

Nu allows you to access native shell programs by escaping the program name with ^.

open Cargo.toml | inc package.version --patch | save - edit file in place

open bands.txt | lines | split-column ":" Band Album Year | skip 1 | sort-by Year

rg -c Tagged | lines | split-column ":" file line_count | str --to-int line_count | sort-by line_count | reverse

open people.txt | lines | split column "|" first_name last_name job | trim | sort-by first_name

open Cargo.lock | from toml

open Cargo.toml --raw - work with raw text

fetch https://www.jonathanturner.org/feed.xml

ls | select name size

ls | sort-by name | nth 5

select - creates a new table which includes only the columns specified

get - returns the values inside the column specified as a list

open rustfmt.toml | insert next_edition 2021 | save rustfmt2.toml

open Cargo.toml | inc package.version --minor | get package.version

The autoview command is appended to any pipeline that doesn’t have an output allowing us to see the result.

^ls - run local cmd, not Nu's equivalent

Alias

alias --save e [msg] { echo $msg }

Math

= 1 + 3

= 1 not-in: [1 2 3]

= "foobar" =~ "foo"

ls | where name in: ["one" "two" "three"] && size > 10kb

Environment

with-env [FOO BAR] { echo $nu.env.FOO }

FOO=BAR echo $nu.env.FOO

Bash

> <path> | save --raw <path> - Save string into a file

cat <path> open --raw <path> - Display the contents of the given file

https://www.nushell.sh/book/en/nushell_map_functional.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment