nushell hacks

nushell hacks

all/any

Work the same way as in rust. Given the predicate, check if all the elements of the list satisfy it.

ansi

The swiss army knife to deal with colored text. Supports raw strings along with some short names and such. Also allows you to specify the shortcodes and such.

You can also specify it in a record, as follows:

let colors = {fg: "#001100", bg: "#FFFFFF", attr: b}

Attributes can be one of bold:bo, blink:bl, blink_fast:bf, normal:n dimmed:d italic:i underline:u reverse:re hidden:h strike:s double_underline:du

ansi reset resets it.

ansi gradient creates a gradient, with the standard options of --(fg/bg)(start/end) to set the corresponding colors.

ansi strip strips all the ansi markers out of the text.

ansi link allows you to create a link for the terminal from the URL piped into it and link text specified in the --text flag.

prepend/append

prepends/appends the specified value to the piped input.

bits

bits have or, and, not, rol, ror, shl, shr, xor subcommands. All of them take the value of the thing to act on as the piped input and the number by which to operate as the argument, and a way to specify the number of bytes using the --number-bytes flag and signedness using --signed.

bytes

This set of commands works with the bytestream type

cal

Interesting command. Prints a calendar. For the specified --full-year, defaults to a single month, unless --full-year is specified.

char

Prints characters from --integer or --unicode codepoints

chunk-by/chunks

The first splits a range or a list based on the predicate, the second does it based on fixed size.

collect

Collects a stream into a value. That's pretty much it.

columns/values

create a list out of the column names/values.

compact

Make the list shorter by removing all the elements that are null.

date

Date command: works with dates and such. Can convert from human time to a datetime using date from-human. This is amazing as it supports multiple formats. date humanize also converts it to a time relative to now.

decode/encode

Decodes/encodes bytes into various encodings. base64 will do a base64 decoding which can be made url-safe by using --url. decode/encode hex will convert a hex string into bytestream/vice-versa.

default

Sets the default values. Can set it for a column in a table or any value in general. Can also use closures.

drop/skip/first/last/select/reject/take

drop drops the last x rows, similarly skip does that for the first x rows. first and last keep the first few rows respectively.

drop supports dropping the nth rows, and can also drop column. skip can skip until or while.

There's also select and reject that can work on the columns. select and reject can also do it for cells in a record. They both feature the --optional flag. take is the same as drop in behaviour.

du

The swiss army knife of filesizes. Has the --min-size flag to ignore really small files, --exclude paths, --long to recurse directories.

each/each while/par-each/enumerate

each is like rust map, and each while basically the closure can return null and the iterator stops. The last one is parallel. Enumerate adds a $index to each of the $item.

error make

Makes an error the same way nushell's internal errors do.

every

Shows (or --skips) every nth row.

explore

Allows you to explore the table. --peek allows you to print the cell Your cursor was on.

explore regex is insane, it lets you interactively develop the regex interactively, and it's awesome for that.

find

Does a regex find basically. Has all the flags relevant for regex. Has explicit support for regex using --regex, and --multiline for multiline matching, --dotall for . to match all, --case-insensitive to do a case insensitive match, --invert to match all that doesn't meet the criteria, and --rfind to find the matches from the reverse but only the first one.

flatten

Flattens a record or a list into a table or a list. Optionally takes column names to flatten along those too. Can also flatten recursively with the --all flag.

format

Name says it all. Has a lot of stuff in it.

from/into

Convert from something/into something else

generate

Takes in a closure, where the argument for the closure is the previous value. Also takes in an initial value.

If an input stream is supplied, the closure takes two arguments, the in and the previous. The next becomes the previous for the closure.

get

Gets the value from the cell path. It can have case insensitive path like --ignore-case and also optional --optional. This can also be enforced at a cell level using ! and ? suffixes.

glob

Lets you search the files and folders in a way similar to how bash globs work. ? replaces one character. * searches for multiple chars, and ** searches for nestings as well.

--depth restricts depth, --no-file and --no-symlink do what you think they do. So does --exclude and --follow-symlinks.

grid

reclaim the bash style ls output using this!

group-by

This lets you group things by their values/columns. If not anything, groups by their raw values themselves. They preserve the original structure as well, so you would want to call an update cells on the result after if you want to remove it. --to-table returns a table with the group and the items column.

hash

Has md5 and sha256 variants, that let you output either plain hex or binary representation of the hash.

headers

Use the first row of the table as column names

hide-env/load-env

Hides an environment variable/load from a record

histogram

Creates a histogram of the input table.

input

Allows you to read input. Yeah. Has a --numchar option that reads specific number of characters, and a --default option that backs the variable by a default value. Default works when the input is empty. Multiline can be entered using --reedline flag.

Has a subcommand called list, that makes an interactive selection. --multi allows you to select multiple of these, --fuzzy allows you to select fuzzy using input, and --index returns the index instead of the item itself.

interleave

Takes in a piped stream (optional), and uses the closures to generate the output and interleave them in arbitrary fashion.

is-empty/is-not-empty/is-terminal/is-admin

go figure

items

Iterate over both keys and values in a record.

job

Relates to background tasks. It can create jobs, list them, find the job, kill, send and receive data over comm channels, tag them, and unfreeze them.

lines

split the input incoming into lines. Can optionally --skip-empty

math

Has a bunch of math functions. Mostly I've used sum and avg subcommands.

merge

merges two records/tables based on the values they provide. Column values are overwritten if needed. Can do it recursively using deep.

move

move columns here and there. Need to use one of --before, --after, --first, --last.

parse

Parse command can parse the input, often automatically, and assign columns based on the format string you provide. Columns can be ignored with {_}, and suppors some fancy regex, where each capture group becomes a column name. The actual regex itself is pretty complicated tbh.

path

Bunch of commands to work with paths.

reduce

Reduce works the same way fold does in OCaml. Initial value is usually the default for the type of stream coming into it. Can specify initial value with --fold

reverse/rotate/roll/transpose

The first one reverses the table columns (and also list). Rotate literally rotates the table clockwise (like a matrix rotation). Can optionally specify --ccw. roll rolls the rows/columns when given up or down/left or right. Specify by how much using the --by flag (default 1). The last is the regular matrix transpose.

seq

Creates a sequence. char will do it for chars, date will do it for dates.

seq takes 3 arguments, begin, step, and end. Or just begin and end. The character variant only takes 2, the last format.

The date variant has a lot of flags. --begin-date and -end-date along with --increment for a specific range. Alternately, you can specify one of the first two along with --days argument. Apart from it, you can also specify one of the first two, and increment, and the --periods that you want the increment for. Can handle --input-format and --output-format as well.

slice

Returns the selected rows (takes a range).

sort/sort-by

Sorts data. --natural sorts by the number value if it's part of a string. --ignore-case, well, does exactly that for strings. --values sorts by values instead. --reverse sorts in reverse.

The latter takes the cell path to sort by, and also takes in comparators for programmatic sorting.

split

Has multiple subcommands

str

Has a bunch of commands to work with, most of them working on the strings and such. Nothing significant as such, with the exception of expand, distance, expand, join, replace (can use regex and closures), substring, and trim. There's a bunch of others like starts-with and ends-with, and reverse and replace and others.

sys/uname

Has a bunch of interesting commands for the system statistics and stuff

timeit

Time the closure

touch

This is interesting because this takes the --timestamp as a datetime, and --reference to use a file's datetime as a reference.

Also possible to change only --modified and --access time. Can let you --no-deref symlinks and --no-create files.

uniq/uniq-by

returns --repeated, --count, --uniqur and optionally --ignore-case. The latter works how sort-by works.

insert/update/upsert

Inserts things. That's pretty much it. Can take a closure too. If it's a table, inserts a new column.

The second updates the values at a particular index, or at a certain column. upsert may also insert if missing.

watch

Watches the file contents and runs a closure (or returns a stream of events if no closure).

window

Creates a sliding window over a list. With the size, the --stride, and optionally the remainder.

wrap

Wraps the given value in a column.

zip

zips two streams. Can also take a closure to generate the second stream from the input.