Skip to content

fix(config): reject a keybindings or menus list with an entry it can't read - #19438

Merged
kronberger-droid merged 6 commits into
nushell:mainfrom
kronberger-droid:feat/config-default-validate-lists
Nov 5, 2026
Merged

kronberger-droid merged 6 commits into
nushell:mainfrom
kronberger-droid:feat/config-default-validate-lists

Conversation

@kronberger-droid

@kronberger-droid kronberger-droid commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow-up to #19418.
A keybinding or menu with a modifier, keycode, mode, layout, input mode or output mode that can't be read used to be accepted and then failed at every prompt.
A fixed copy that a reload appended did not replace it, since ++= only adds, thus Tab stayed broken until a restart.

Assigning such a list is now rejected as a whole and the previous list stays, like for any other config value that can't be read.
The grammar moved from nu-cli to nu-protocol (config/key_spec.rs) for that, since nu-protocol has no crossterm, and nu-cli only maps it onto reedline's types.

This also adds config default, which returns the default config as a record.
A config that gets sourced again needs it to start from the defaults, and it replaces the ^$nu.current-exe -n -c ... hack in doc_config.nu.

User-facing changes (Release notes)

Invalid keybindings and menus are rejected on assignment

  • Assigning $env.config.keybindings or $env.config.menus with an entry that can't be read is now an error, and the old list is kept.
    That covers the modifier, keycode and mode of a keybinding, and the layout, input_mode (or only_buffer_difference) and output_mode of a menu.
    Before, it was accepted and failed on every prompt.
    In config.nu, the lines after the rejected assignment don't run.

  • A menu without a layout, such as type: {}, is rejected on assignment now.

  • New command config default, which returns the default config as a record.
    A config that is sourced again adds its ++= entries each time, and = drops the defaults, so start from the defaults to keep the list stable:

    $env.config.keybindings = (config default).keybindings
    $env.config.keybindings ++= $custom

Additional notes

Unit tests in nu-protocol cover the grammar and the rejected lists, and repl tests cover the reload scenario.

Out of scope:

  • event and the fields of one menu layout (columns, page_size, description_position) are still read when the prompt is built.
  • The error names the first bad entry and not the setting. One error per bad entry would be a follow-up.
  • nu-tui still reads keybinding strings with its own looser rules (normalize_binding).

Since assigning `$env.config.keybindings` or `menus` replaces the list,
there was no way back to the defaults in a running shell short of
spawning `nu -n`. `(config default).keybindings` is the list nushell
ships, so assigning it restores the defaults, and a config that starts
with that line before its `++=` entries builds the same list each time
it is sourced instead of growing it.

It holds the entries nushell adds, such as the Tab completion menu, and
not reedline's own base bindings, which `keybindings default` lists.
…t read

A keybinding or menu with a modifier, keycode, mode or layout that
can't be read used to be accepted by the assignment and then fail every
prompt, thus a fixed copy that a reload appended later did not replace
it and Tab stayed broken until a restart. Assigning such a list is now
rejected as a whole and the previous list stays, like any config value
that can't be read.

The grammar moved from `nu-cli` to `nu-protocol`, which has no
`crossterm`, and `nu-cli` maps it onto reedline's types, so both read an
entry the same way. An `event` needs reedline's types and is still read
when the prompt is built.

A menu without a `layout`, such as `type: {}`, is rejected on assignment
now. It only failed at the prompt before.
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Hey, just a bot checking in! You edited files related to the configuration.
If you changed any of the default values or added a new config option, don't forget to update the doc_config.nu which documents the options for our users including the defaults provided by the Rust implementation.
If you didn't make a change here, you can just ignore me.

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

Rejecting a bad layout on assignment does what the PR says: a reload with the fixed copy gets Tab back, where main stays stuck. config default matches the $env.config of a fresh nu -n with no differences. Left to do: the new command breaks a nu-lsp test, and other menu fields still get stuck until a restart.

Findings: 0 High severity · 2 Medium severity · 4 Low severity

Open (6)

Notes from my clanker, checked on 5bd32dd. Built the branch and ran cargo test -p nu-protocol --lib -- config (50 passed), -p nu-cli --lib -- reedline_config (36 passed), -p nu-command --lib -- config_default (1 passed), --test tests -- repl::test_config (59 passed) and -p nu-lsp --lib (112 passed, 1 failed). Clippy with CI's flags on nu-protocol, nu-cli and nu-command is clean, and so are fmt and typos. Each case ran on the branch binary and on main (c27defb), the prompt cases in a real REPL through a pty. I didn't run the rest of the workspace tests or anything on Linux or Windows.

Comment thread crates/nu-protocol/src/config/mod.rs Resolved
Comment thread crates/nu-cli/src/reedline_config.rs Resolved
A menu with an `input_mode`, `only_buffer_difference` or `output_mode` that can't be read was still accepted and only failed when the prompt was built, thus a fixed copy appended on reload did not replace it. The names moved to `key_spec.rs` next to `MenuLayout` and `nu-cli` maps them onto reedline's types. The fields that belong to one layout, such as `columns`, are still read at the prompt.

From review: the keycode error lists the valid names instead of naming crossterm, `doc_config.nu` says a rejected assignment stops `config.nu` at that line, the `nu-lsp` completion test expects `config default` as the second `config ` entry, and tests that repeated others are dropped.
@kronberger-droid

kronberger-droid commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Fine to land from my side. Included most of the review points. @fdncred

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

All 6 threads are resolved on 1e06717. Five are fixed, and the error-reporting one moves to the follow-up we agreed on. A bad input_mode, output_mode or only_buffer_difference is now rejected on assignment, and a reload with the fixed copy brings Tab back. Two new lows are left, both about wording.

Findings: 0 High severity · 0 Medium severity · 2 Low severity

Open (2)

Notes from my clanker, checked on 1e06717. Built the branch and ran probe.sh, recheck.sh, menu_fields.sh and new recheck2.sh and recheck3.sh against it and main (c27defb) on macOS, including Tab at a live REPL prompt for each input and output mode. cargo test -p nu-lsp --lib gives 113 passed. With the keycode suggestion applied locally, cargo test -p nu-protocol --lib key_spec gives 15 passed; I reverted it after. CI is green on this head, so I didn't run clippy or the full test suite myself, and Linux and Windows rest on CI.

Comment thread crates/nu-protocol/src/config/mod.rs Resolved
@kronberger-droid
kronberger-droid merged commit 47ad8aa into nushell:main Nov 5, 2026
12 checks passed
@github-actions github-actions Bot added this to the v0.117.0 milestone Nov 5, 2026
@kronberger-droid kronberger-droid added notes:ready Indicates Ready for Release notes notes:fixes Noted in "Bug fixes" section labels Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants