diff --git a/blog/2024-12-24-nushell_0_101_0.md b/blog/2024-12-24-nushell_0_101_0.md index 94d68e974fa..ab7dcc87421 100644 --- a/blog/2024-12-24-nushell_0_101_0.md +++ b/blog/2024-12-24-nushell_0_101_0.md @@ -71,6 +71,117 @@ There may be (hopefully) minor breaking changes due to the startup configuration With [#14295](https://github.com/nushell/nushell/pull/14295), dates can now be added to durations. Previously only durations could be added to dates. +### `group-by` + +::: warning Breaking change +See a full overview of the [breaking changes](#breaking-changes) +::: + +Thanks to [@Bahex](https://github.com/Bahex) in [#14337](https://github.com/nushell/nushell/pull/14337), the `group-by` command now supports grouping by multiple criteria (henceforth referred to as grouper). +When using multiple groupers, the output is in the form of nested records. + +```nu +[ + [category color name]; + [fruit red apple] + [fruit red strawberry] + [vegetable red tomato] + [fruit orange orange] + [vegetable orange carrot] + [vegetable orange pumpkin] +] | group-by color category +``` +``` +╭────────┬───────────────────────────────────────────────────────╮ +│ │ ╭───────────┬───────────────────────────────────────╮ │ +│ red │ │ │ ╭───┬──────────┬───────┬────────────╮ │ │ +│ │ │ fruit │ │ # │ category │ color │ name │ │ │ +│ │ │ │ ├───┼──────────┼───────┼────────────┤ │ │ +│ │ │ │ │ 0 │ fruit │ red │ apple │ │ │ +│ │ │ │ │ 1 │ fruit │ red │ strawberry │ │ │ +│ │ │ │ ╰───┴──────────┴───────┴────────────╯ │ │ +│ │ │ │ ╭───┬───────────┬───────┬────────╮ │ │ +│ │ │ vegetable │ │ # │ category │ color │ name │ │ │ +│ │ │ │ ├───┼───────────┼───────┼────────┤ │ │ +│ │ │ │ │ 0 │ vegetable │ red │ tomato │ │ │ +│ │ │ │ ╰───┴───────────┴───────┴────────╯ │ │ +│ │ ╰───────────┴───────────────────────────────────────╯ │ +│ │ ╭───────────┬──────────────────────────────────────╮ │ +│ orange │ │ │ ╭───┬──────────┬────────┬────────╮ │ │ +│ │ │ fruit │ │ # │ category │ color │ name │ │ │ +│ │ │ │ ├───┼──────────┼────────┼────────┤ │ │ +│ │ │ │ │ 0 │ fruit │ orange │ orange │ │ │ +│ │ │ │ ╰───┴──────────┴────────┴────────╯ │ │ +│ │ │ │ ╭───┬───────────┬────────┬─────────╮ │ │ +│ │ │ vegetable │ │ # │ category │ color │ name │ │ │ +│ │ │ │ ├───┼───────────┼────────┼─────────┤ │ │ +│ │ │ │ │ 0 │ vegetable │ orange │ carrot │ │ │ +│ │ │ │ │ 1 │ vegetable │ orange │ pumpkin │ │ │ +│ │ │ │ ╰───┴───────────┴────────┴─────────╯ │ │ +│ │ ╰───────────┴──────────────────────────────────────╯ │ +╰────────┴───────────────────────────────────────────────────────╯ +``` + +With the `--to-table` flag, instead of nested records, the output is in the form of a table with columns corresponding to each grouper and the `items` column. +Each column corresponding to a `grouper` is named after it. For closure groupers, the columns are named with the scheme `closure_{i}`. + +```nu +.. | group-by color category --to-table +``` +``` +╭───┬────────┬───────────┬───────────────────────────────────────╮ +│ # │ color │ category │ items │ +├───┼────────┼───────────┼───────────────────────────────────────┤ +│ 0 │ red │ fruit │ ╭───┬──────────┬───────┬────────────╮ │ +│ │ │ │ │ # │ category │ color │ name │ │ +│ │ │ │ ├───┼──────────┼───────┼────────────┤ │ +│ │ │ │ │ 0 │ fruit │ red │ apple │ │ +│ │ │ │ │ 1 │ fruit │ red │ strawberry │ │ +│ │ │ │ ╰───┴──────────┴───────┴────────────╯ │ +│ 1 │ red │ vegetable │ ╭───┬───────────┬───────┬────────╮ │ +│ │ │ │ │ # │ category │ color │ name │ │ +│ │ │ │ ├───┼───────────┼───────┼────────┤ │ +│ │ │ │ │ 0 │ vegetable │ red │ tomato │ │ +│ │ │ │ ╰───┴───────────┴───────┴────────╯ │ +│ 2 │ orange │ fruit │ ╭───┬──────────┬────────┬────────╮ │ +│ │ │ │ │ # │ category │ color │ name │ │ +│ │ │ │ ├───┼──────────┼────────┼────────┤ │ +│ │ │ │ │ 0 │ fruit │ orange │ orange │ │ +│ │ │ │ ╰───┴──────────┴────────┴────────╯ │ +│ 3 │ orange │ vegetable │ ╭───┬───────────┬────────┬─────────╮ │ +│ │ │ │ │ # │ category │ color │ name │ │ +│ │ │ │ ├───┼───────────┼────────┼─────────┤ │ +│ │ │ │ │ 0 │ vegetable │ orange │ carrot │ │ +│ │ │ │ │ 1 │ vegetable │ orange │ pumpkin │ │ +│ │ │ │ ╰───┴───────────┴────────┴─────────╯ │ +╰───┴────────┴───────────┴───────────────────────────────────────╯ +``` + +### `path self` + +Thanks to [@Bahex](https://github.com/Bahex) in [#14303](https://github.com/nushell/nushell/pull/14303), this release adds the `path self` command. +`path self` is a parse-time only command for getting the absolute path of the source file containing it, or any file relative to the source file. + +```nushell +const this_file = path self +const this_directory = path self . +``` + +### `term query` +Thanks to [@Bahex](https://github.com/Bahex) in [#14427](https://github.com/nushell/nushell/pull/14427), this release adds the `term query` command. +`term query` allows sending a query to your terminal emulator and reading the reply. + +```nushell +# Get cursor position +term query (ansi cursor_position) --prefix (ansi csi) --terminator 'R' + +# Get terminal background color. +term query $'(ansi osc)10;?(ansi st)' --prefix $'(ansi osc)10;' --terminator (ansi st) + +# Read clipboard content on terminals supporting OSC-52. +term query $'(ansi osc)52;c;?(ansi st)' --prefix $'(ansi osc)52;c;' --terminator (ansi st) +``` + ## Breaking changes ### `++` operator @@ -124,6 +235,47 @@ To make the deferred evaluation more explicit, the `timeit` command can now only The `cpu_usage` column outputted by `sys cpu` works by sampling the CPU over a 400ms period. This wait long time is unhelpful if you are only interested in other information about the CPU like the number of cores (i.e., `sys cpu | length`). With [#14485](https://github.com/nushell/nushell/pull/14485), the `cpu_usage` column is now gated behind the `--long` flag. This way, `sys cpu` will take around 0-2ms instead of 400ms by default. +### `from csv` and `from tsv` +Thanks to [@Bahex](https://github.com/Bahex) in [#14399](https://github.com/nushell/nushell/pull/14399), parsing csv and tsv content with the `--flexible` flag is more flexible than before. +Previously, the first row of csv or tsv content would determine the number of columns, and rows containing more values than the determined columns would be truncated, losing those extra values. + +With this release, that is no longer the case. +Now, `--flexible` flag means the number of columns aren't limited by the first row and can have not just less but also more values than the first row. + +```csv +value +1,aaa +2,bbb +3 +4,ddd +5,eee,extra +``` +```nu +.. | from csv --flexible --noheaders +``` +``` +╭─#─┬─column0─┬─column1─┬─column2─╮ +│ 0 │ value │ ❎ │ ❎ │ +│ 1 │ 1 │ aaa │ ❎ │ +│ 2 │ 2 │ bbb │ ❎ │ +│ 3 │ 3 │ ❎ │ ❎ │ +│ 4 │ 4 │ ddd │ ❎ │ +│ 5 │ 5 │ eee │ extra │ +╰─#─┴─column0─┴─column1─┴─column2─╯ +``` + +### `std/iter scan` + +Thanks to [@Bahex](https://github.com/Bahex) in [#14596](https://github.com/nushell/nushell/pull/14596), the order of `scan`'s closure's parameters are flipped to be consistent with `reduce`. +The closure now also receives the accumulator value as pipeline input as well. + +```nushell +> [a b c d] | iter scan "" {|x, y| [$x, $y] | str join} -n +# To keep its behavior same, this command should be changed to either of the following +> [a b c d] | iter scan "" {|it, acc| [$acc, $it] | str join} -n +> [a b c d] | iter scan "" {|it| append $it | str join} -n +``` + ## Deprecations ### `split-by` @@ -172,20 +324,19 @@ Thanks to all the contributors below for helping us solve issues, improve docume |[@132ikl](https://github.com/132ikl)|Change tests which may invoke externals to use non-conflicting names|[#14516](https://github.com/nushell/nushell/pull/14516)| - - +|[@Bahex](https://github.com/Bahex)|Add `path self` command for getting absolute paths to files at parse time|[#14303](https://github.com/nushell/nushell/pull/14303)| +|[@Bahex](https://github.com/Bahex)|add multiple grouper support to `group-by`|[#14337](https://github.com/nushell/nushell/pull/14337)| |[@Bahex](https://github.com/Bahex)|fix(group-by): re #14337 name collision prevention|[#14360](https://github.com/nushell/nushell/pull/14360)| - - - - - - - +|[@Bahex](https://github.com/Bahex)|truly flexible csv/tsv parsing|[#14399](https://github.com/nushell/nushell/pull/14399)| +|[@Bahex](https://github.com/Bahex)|Add `term query`, for querying information from terminals.|[#14427](https://github.com/nushell/nushell/pull/14427)| +|[@Bahex](https://github.com/Bahex)|`term query`: refactor, add `--prefix` flag|[#14446](https://github.com/nushell/nushell/pull/14446)| +|[@Bahex](https://github.com/Bahex)|Propagate existing errors in insert and merge|[#14453](https://github.com/nushell/nushell/pull/14453)| +|[@Bahex](https://github.com/Bahex)|lsp and --ide-check fix for `path self` related diagnostics|[#14538](https://github.com/nushell/nushell/pull/14538)| |[@Bahex](https://github.com/Bahex)|docs(reduce): add example demonstrating accumulator as pipeline input|[#14593](https://github.com/nushell/nushell/pull/14593)| +|[@Bahex](https://github.com/Bahex)|remove the deprecated index argument from filter commands' closure signature|[#14594](https://github.com/nushell/nushell/pull/14594)| +|[@Bahex](https://github.com/Bahex)|`std/iter scan`: change closure signature to be consistent with `reduce`|[#14596](https://github.com/nushell/nushell/pull/14596)| - |[@DziubaMaksym](https://github.com/DziubaMaksym)|fix: sample_config|[#14465](https://github.com/nushell/nushell/pull/14465)|