Skip to content

Don't fail to merge abbreviations that the user already defined - #1296

Merged
fdncred merged 1 commit into
nushell:mainfrom
DavSanchez:fix/abbreviations-merge-user-config
Oct 21, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
DavSanchez:fix/abbreviations-merge-user-config

Conversation

@DavSanchez

Copy link
Copy Markdown
Contributor

The abbreviation files merge their contents into the user's config with a
record spread:

$env.config.abbreviations = {
    ...$git_abbreviations
    ...$env.config.abbreviations
}

That precedence (user config wins) is right, but the spread errors when a
key exists in both records instead of overriding it:

$env.config.abbreviations = { grbm: "git rebase main" }
source ./git-abbreviations.nu
# Error: nu::shell::column_defined_twice
#   x Record field or table column used twice: grbm

So a user cannot override an abbreviation before sourcing the file (which
is the documented way to keep config in config.nu), and sourcing the same
file twice fails too.

merge keeps the same precedence and doesn't care about duplicate keys:

$env.config.abbreviations = ($git_abbreviations | merge $env.config.abbreviations)

Verified on nushell 0.116.1 for all six abbreviation files: sourcing twice and
pre-defining a key both work, and the user's value still wins.

All the `*-abbreviations.nu` files merged their abbreviations with
`{...$abbreviations ...$env.config.abbreviations}`. If the user had
already defined any of those abbreviations (for example in
`config.nu`, before sourcing the file, or by sourcing the same file
twice), nushell rejects the record literal with:

    Error: nu::shell::column_defined_twice
      x Record field or table column used twice: grbm

`merge` keeps the same precedence (the user's value wins) without
erroring on duplicate keys.
@fdncred

fdncred commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

good idea. ping me when you're ready

@DavSanchez
DavSanchez marked this pull request as ready for review October 21, 2026 17:22
@DavSanchez

Copy link
Copy Markdown
Contributor Author

@fdncred ready for review!

@fdncred
fdncred merged commit e055e4c into nushell:main Oct 21, 2026
1 check passed
@fdncred

fdncred commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants