Repository navigation
fix(config)!: make assigning keybindings and menus replace the list - #19418
Conversation
|
Hey, just a bot checking in! You edited files related to the configuration. |
06dc130 to
5115138
Compare
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
=, ++=, filtering and = [] do what the PR says on both lists, and ++= keeps Tab completion working. One regression: a broken menu or keybinding now outlives a later fix, so reloading a fixed config no longer recovers. The rest is docs.
Findings: 0
Open (4)
Notes from my clanker, checked on 5115138. Built the branch (its reedline fork is 8bc5cd0 plus nushell/reedline#1294 and nothing else) and ran each case on it and on 0.116.2, with Tab checked in a real REPL. CI already ran fmt, clippy and the tests on all three OSes, so I didn't rerun them. The security_audit failure is calamine's RUSTSEC-2026-0436, which fails on main too.
| // Stored as written, like any list. Reedline registers the | ||
| // menus in order, so a later one wins on a name. | ||
| "menus" => match Vec::<ParsedMenu>::from_value(val.clone()) { | ||
| Ok(menus) => { | ||
| for menu in menus { | ||
| let target_name = menu.name.to_expanded_string("", self); | ||
|
|
||
| let found_index = self.menus.iter().position(|existing_menu| { | ||
| existing_menu.name.to_expanded_string("", self) == target_name | ||
| }); | ||
|
|
||
| if let Some(index) = found_index { | ||
| self.menus[index] = menu; | ||
| } else { | ||
| self.menus.push(menu); | ||
| } | ||
| } | ||
| } | ||
| Ok(menus) => self.menus = menus, |
There was a problem hiding this comment.
On 5115138, a later entry doesn't replace an earlier broken one. Every entry still gets built, so the broken one fails first. You hit this when you fix an entry in config.nu and reload it, because ++= appends the fixed copy after the broken one.
Menus:
# menu_bad.nu: $env.config.menus ++= [{name: completion_menu, only_buffer_difference: false, marker: "X ", type: {layout: grid}, style: {}}]
# menu_fixed.nu: the same with `layout: columnar`
source menu_bad.nu; source menu_fixed.nu
$env.config.menus | where name == completion_menu | get type.layout | to nuon
# main: [columnar]
# branch: [columnar, grid, columnar]
# then `"ab" | str capitali<Tab><Enter>` in the REPL
# main: completes to `str capitalize`, prints Ab
# branch: `expected 'columnar', 'list', 'ide', or 'description', but got 'grid'` at every prompt, and Tab does nothingKeybindings, same name and key with a bad event first:
# kb_bad_event.nu: $env.config.keybindings ++= [{name: my_binding, modifier: control, keycode: char_t, mode: emacs, event: {send: bogus}}]
# kb_fixed.nu: the same with `event: {send: clearscreen}`
source kb_bad_event.nu; source kb_fixed.nu
$env.config.keybindings | where name == my_binding | get event.send | to nuon
# main: [clearscreen], and no error at the next prompt
# branch: [bogus, clearscreen], and `expected a reedline event, but got 'bogus'` at every promptOn main the merge replaced the broken entry, so reloading the fixed config (source $nu.config-path, or an F5 binding that runs it) recovered. On the branch it stays broken until a restart or a where filter, even though doc_config.nu says the last entry wins.
For menus, building only the last menu for each name in add_menus (reedline_config.rs:37) makes that hold for broken menus too:
for (i, menu) in config.menus.iter().enumerate() {
let name = menu.name.to_expanded_string("", &config);
// A later menu with this name replaces this one, so don't build it.
if config.menus[i + 1..]
.iter()
.any(|later| later.name.to_expanded_string("", &config) == name)
{
continue;
}
line_editor = add_menu(line_editor, menu, engine_state_ref.clone(), stack, config.clone())?
}I tried this as a trial patch on the branch: after the same reload, Tab completes again and the error is gone. It also stops building the shadowed copies on every prompt, and it gives nushell a test for the last-wins rule instead of leaning only on the reedline one.
For keybindings the key decides, not the name, so create_keybindings would have to walk the list from the end and skip a mode and key that a later entry already set. That gives the same last-wins result, and it never reads the shadowed entry's event.
There was a problem hiding this comment.
@fdncred
How about checking the entries when the list is assigned and rejecting the whole list if one is faulty, like table.mode = "bogus" errors and keeps the old value?
That covers modifier, keycode and mode (and a menu's layout), thus a reload with a fixed config recovers, but events like {send: bogus} would still only fail when the prompt is built.
|
I also have a PR for the security audit cooking right now Note: it landed #19420 - just need to merge main to get the ci green |
|
I also wonder about this keybinding that I have. Seems like it duplicates menus and keybindings. {
name: reload_config
modifier: none
keycode: f5
mode: [emacs vi_normal vi_insert]
event: {
send: executehostcommand,
cmd: $"source '($nu.env-path)';source '($nu.config-path)'"
}
}Does |
## Description The `Security audit` job fails on every PR that touches `Cargo.toml` or `Cargo.lock` (for example #19418), and on main's lockfile too. The advisory database now flags calamine 0.37.0 with RUSTSEC-2026-0436: a crafted file can make calamine's CFB/OLE2 reader panic or try to allocate several gigabytes. calamine 0.38.0 fixes it. nushell can hit this bug. `from xlsx` runs the CFB reader on every input to check for password protection, so the upstream fixture `cfb_dir_short_chunk_panic.xls` (calamine PR #762) crashes the shell on main. | Crate | Old | New | Advisory | Pulled in by | | --- | --- | --- | --- | --- | | `calamine` | 0.37.0 | 0.38.0 | RUSTSEC-2026-0436 | `nu-command` (`from xlsx`, `from ods`) | ## User-facing changes (Release notes) - `from ods` now returns a formula error cell's text (such as `#DIV/0!`) instead of an empty string, and keeps tabs and line breaks inside cell text. - Fixed `from xlsx` crashing nushell or running out of memory on a crafted file. It now reports `Could not load XLSX file` (RUSTSEC-2026-0436). ## Additional notes <!-- Optional. Examples: - fixes #123 - closes #456 - related #789 Anything else reviewers should know. Remove this section if not needed. -->
5115138 to
bc4205e
Compare
Since nushell#18761 assigning `$env.config.keybindings` merged into the current list, thus no assignment could drop a single binding, and a binding with a bad keycode errored on every prompt until the whole list was cleared. The list is now stored as written, like any other list: `=` replaces it, `++=` appends and a filtered list drops what it filtered out. Reedline applies the entries in order on top of its base maps, so the last entry on a key wins, in each mode it names. A name is only a label. `= [mine]` now drops the default menu bindings as well, since nushell#18747 moved them into the list. Use `++=` to keep them. `SharedKeybindingName` goes: one name on several keys (atuin) is no longer ambiguous once nothing merges by name.
Brings in nushell/reedline#1294, which the menus commit after this one relies on.
Same semantics as the keybindings commit before it: the list is stored as written, thus `=` replaces it, `= [mine]` drops the defaults and `++=` keeps them. A menu added under a taken name overrides it, since reedline registers the menus in order and the last one under a name wins (nushell/reedline#1294). That needs the reedline bump below this commit.
bc4205e to
4312b18
Compare
|
@fdncred Also yeah if you reload with a My idea behind this implementation was to make no special casing and treat both menus and keybindings just like lists. $env.config.keybindings = $env.config.keybindings | where name? != reload_config | append {...}My idea would be similar to your suggestion on discord, make |
|
I'm fine with keybinding commands as follow ups but I don't really like the idea of an ever growing list of keybindings and menus. I think we should deduplicate in code before merging. My keybinding doesn't do ++=, is just sources config.nu and env.nu. |
|
Well then it depends on how you set keybindings in your config. If you don't dedup there but just do
|
|
I would prefer just making it easy, but explicit to dedup. |
|
In my mind the only thing that is really missing is a way to get the defaults as data, since the only way today is $env.config.keybindings = (<defaults>)
$env.config.keybindings ++= [mine] |
|
I don't use |
|
Well with plain |
|
Just what I was speculating, I don't get dupes now with I think we're good to go now with this incremental change. If we need/want to dedupe in the future we still can. |
…t read (#19438) ## 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) - 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: ```nu $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`). --------- Co-authored-by: Darren Schroeder <[email protected]>
…ults Nushell 0.117.0 (nushell/nushell#19418) made assigning keybindings/menus inside $env.config = {...} replace the whole list, including the default bindings that open Tab completion, Ctrl+Space, F1 help, Ctrl+X/Z paging, and Ctrl+R history. Switch to $env.config.menus ++= / keybindings ++= so custom entries add to the defaults instead of wiping them.



Description
Since #18761 assigning
$env.config.keybindingsor$env.config.menusmerges into the current list in the config layer.That made the two lists behave unlike every other list in nushell:
=could not drop a single binding,menus = []cleared nothing, and a binding with a bad keycode errored on every prompt until the whole list was cleared.#18828 and #18870 patched the merge (unnamed bindings, then name plus key, with a warning for atuin's shared names in #18848), but each patch added a rule on top of the merge.
This PR takes the merge out.
Both lists are stored as written, like any other list:
Overlaps are resolved where the list is used, by reedline, with one rule for both lists: entries are applied in order and the last one wins.
Keys already worked like this in reedline, since
add_bindingis aHashMap::insert.Menus did not, since the lookup by name takes the first match, so nushell/reedline#1294 made a later menu replace one of the same name.
A keybinding's
nameis only a label and plays no part in what a key does.SharedKeybindingNamegoes, since one name on several keys (atuin) is no longer ambiguous once nothing merges by name.The
KeyIdentitymachinery that mirrored reedline's key parsing goes with it.For keybindings there is a test where nushell hands the list over:
create_keybindingsis checked for last-wins, forevent: nullremoving a reedline base binding, and for a later entry covering fewer modes.Menus rely on the reedline test for the same rule, since nushell only passes the list on.
User-facing changes (Release notes)
Assigning
$env.config.keybindingsand$env.config.menusreplaces the listBreaking:
$env.config.keybindings = [...]and$env.config.menus = [...]now replace the whole list, including nushell's default menus and the keys that open them (Tab and Shift+Tab completion, Ctrl+Space, F1 help, Ctrl+X and Ctrl+Z paging, the Ctrl+R history menu).If your config assigns either list, or sets
keybindingsormenusinside a$env.config = {...}record, switch to++=or Tab stops completing.Reedline's own bindings (movement, editing) are not part of the list and stay.
To get the defaults back in a running shell, assign them again from a clean
nu -n:Filtering a list now removes what it drops, and
= []clears either list.When several keybindings bind the same key in the same mode, or several menus share a name, the last one wins.
A keybinding's
nameis only a label, so sharing one between keys no longer warns.To unbind a key that reedline itself binds, add an entry for it with
event: null.Additional notes
Menus need nushell/reedline#1294, which is in the reedline bump commit before the menus commit.
The book still describes the merge in
line_editor.md(the keybindings section and the menus note), so that needs a follow-up PR to nushell.github.io.Related: #18761, #18828, #18870, #18848.