nushell/crates
Bahex c4dcfdb77b
feat!: Explicit cell-path case sensitivity syntax (#15692)
Related:
- #15683
- #14551
- #849
- #12701
- #11527

# Description
Currently various commands have differing behavior regarding cell-paths

```nushell
{a: 1, A: 2} | get a A
# => ╭───┬───╮
# => │ 0 │ 2 │
# => │ 1 │ 2 │
# => ╰───┴───╯
{a: 1, A: 2} | select a A
# => ╭───┬───╮
# => │ a │ 1 │
# => │ A │ 2 │
# => ╰───┴───╯
{A: 1} | update a 2
# => Error: nu:🐚:column_not_found
# => 
# =>   × Cannot find column 'a'
# =>    ╭─[entry #62:1:1]
# =>  1 │ {A: 1} | update a 2
# =>    · ───┬──          ┬
# =>    ·    │            ╰── cannot find column 'a'
# =>    ·    ╰── value originates here
# =>    ╰────
```

Proposal: making cell-path access case-sensitive by default and adding
new syntax for case-insensitive parts, similar to optional (?) parts.

```nushell
{FOO: BAR}.foo
# => Error: nu:🐚:name_not_found
# => 
# =>   × Name not found
# =>    ╭─[entry #60:1:21]
# =>  1 │ {FOO: BAR}.foo
# =>    ·            ─┬─
# =>    ·             ╰── did you mean 'FOO'?
# =>    ╰────
{FOO: BAR}.foo!
# => BAR
```

This would solve the problem of case sensitivity for all commands
without causing an explosion of flags _and_ make it more granular

Assigning to a field using a case-insensitive path is case-preserving.
```nushell
mut val = {FOO: "I'm FOO"}; $val
# => ╭─────┬─────────╮
# => │ FOO │ I'm FOO │
# => ╰─────┴─────────╯
$val.foo! = "I'm still FOO"; $val
# => ╭─────┬───────────────╮
# => │ FOO │ I'm still FOO │
# => ╰─────┴───────────────╯
```

For `update`, case-insensitive is case-preserving.
```nushell
{FOO: 1} | update foo! { $in + 1 }
# => ╭─────┬───╮
# => │ FOO │ 2 │
# => ╰─────┴───╯
```

`insert` can insert values into nested values so accessing into existing
columns is case-insensitive, but creating new columns uses the cell-path
as it is.
So `insert foo! ...` and `insert FOO! ...` would work exactly as they do
without `!`
```nushell
{FOO: {quox: 0}}
# => ╭─────┬──────────────╮
# => │     │ ╭──────┬───╮ │
# => │ FOO │ │ quox │ 0 │ │
# => │     │ ╰──────┴───╯ │
# => ╰─────┴──────────────╯
{FOO: {quox: 0}} | insert foo.bar 1
# => ╭─────┬──────────────╮
# => │     │ ╭──────┬───╮ │
# => │ FOO │ │ quox │ 0 │ │
# => │     │ ╰──────┴───╯ │
# => │     │ ╭─────┬───╮  │
# => │ foo │ │ bar │ 1 │  │
# => │     │ ╰─────┴───╯  │
# => ╰─────┴──────────────╯
{FOO: {quox: 0}} | insert foo!.bar 1
# => ╭─────┬──────────────╮
# => │     │ ╭──────┬───╮ │
# => │ FOO │ │ quox │ 0 │ │
# => │     │ │ bar  │ 1 │ │
# => │     │ ╰──────┴───╯ │
# => ╰─────┴──────────────╯
```

`upsert` is tricky, depending on the input, the data might end up with
different column names in rows. We can either forbid case-insensitive
cell-paths for `upsert` or trust the user to keep their data in a
sensible shape.

This would be a breaking change as it would make existing cell-path
accesses case-sensitive, however the case-sensitivity is already
inconsistent and any attempt at making it consistent would be a breaking
change.

> What about `$env`?

1. Initially special case it so it keeps its current behavior.
2. Accessing environment variables with non-matching paths gives a
deprecation warning urging users to either use exact casing or use the
new explicit case-sensitivity syntax
3. Eventuall remove `$env`'s special case, making `$env` accesses
case-sensitive by default as well.

> `$env.ENV_CONVERSIONS`?

In addition to `from_string` and `to_string` add an optional field to
opt into case insensitive/preserving behavior.

# User-Facing Changes

- `get`, `where` and other previously case-insensitive commands are now
case-sensitive by default.
- `get`'s `--sensitive` flag removed, similar to `--ignore-errors` there
is now an `--ignore-case` flag that treats all parts of the cell-path as
case-insensitive.
- Users can explicitly choose the case case-sensitivity of cell-path
accesses or commands.

# Tests + Formatting

Existing tests required minimal modification. ***However, new tests are
not yet added***.

- 🟢 toolkit fmt
- 🟢 toolkit clippy
- 🟢 toolkit test
- 🟢 toolkit test stdlib

# After Submitting

- Update the website to include the new syntax
- Update [tree-sitter-nu](https://github.com/nushell/tree-sitter-nu)

---------

Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
2025-05-18 12:19:09 +03:00
..
nu_plugin_custom_values Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu_plugin_example Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu_plugin_formats Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu_plugin_gstat Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu_plugin_inc feat!: Explicit cell-path case sensitivity syntax (#15692) 2025-05-18 12:19:09 +03:00
nu_plugin_javascript create nu_plugin_node_example.js (#15482) 2025-04-11 21:18:46 +02:00
nu_plugin_nu_example feat: make to nuon raw option remove all white space (#15609) 2025-05-09 09:38:24 +08:00
nu_plugin_polars feat(polars): expand polars unique to allow expressions inputs (#15771) 2025-05-17 12:26:26 -04:00
nu_plugin_python Bump to 0.104.1 dev version (#15669) 2025-04-29 23:33:10 -04:00
nu_plugin_query Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu_plugin_stress_internals Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-cli feat!: Explicit cell-path case sensitivity syntax (#15692) 2025-05-18 12:19:09 +03:00
nu-cmd-base Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-cmd-extra feat!: Explicit cell-path case sensitivity syntax (#15692) 2025-05-18 12:19:09 +03:00
nu-cmd-lang Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-cmd-plugin Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-color-config Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-command feat!: Explicit cell-path case sensitivity syntax (#15692) 2025-05-18 12:19:09 +03:00
nu-derive-value Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-engine feat!: Explicit cell-path case sensitivity syntax (#15692) 2025-05-18 12:19:09 +03:00
nu-explore Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-glob Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-json Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-lsp feat!: Explicit cell-path case sensitivity syntax (#15692) 2025-05-18 12:19:09 +03:00
nu-parser feat!: Explicit cell-path case sensitivity syntax (#15692) 2025-05-18 12:19:09 +03:00
nu-path Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-plugin Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-plugin-core Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-plugin-engine Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-plugin-protocol Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-plugin-test-support Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-pretty-hex Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-protocol feat!: Explicit cell-path case sensitivity syntax (#15692) 2025-05-18 12:19:09 +03:00
nu-std fix kv set examples (#15769) 2025-05-17 23:31:46 -04:00
nu-system Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-table fix: empty tables now respect $env.config.use_ansi_coloring (closes #14896) (#15751) 2025-05-14 06:40:15 -05:00
nu-term-grid Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-test-support Rust 1.85, edition=2024 (#15741) 2025-05-13 16:49:30 +02:00
nu-utils feat!: Explicit cell-path case sensitivity syntax (#15692) 2025-05-18 12:19:09 +03:00
nuon feat!: Explicit cell-path case sensitivity syntax (#15692) 2025-05-18 12:19:09 +03:00
README.md Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00

Nushell core libraries and plugins

These sub-crates form both the foundation for Nu and a set of plugins which extend Nu with additional functionality.

Foundational libraries are split into two kinds of crates:

  • Core crates - those crates that work together to build the Nushell language engine
  • Support crates - a set of crates that support the engine with additional features like JSON support, ANSI support, and more.

Plugins are likewise also split into two types:

  • Core plugins - plugins that provide part of the default experience of Nu, including access to the system properties, processes, and web-connectivity features.
  • Extra plugins - these plugins run a wide range of different capabilities like working with different file types, charting, viewing binary data, and more.