Skip to content

feat: fish-style abbreviations#18197

Merged
fdncred merged 11 commits into
nushell:mainfrom
casedami:feat-abbreviations
May 21, 2026
Merged

feat: fish-style abbreviations#18197
fdncred merged 11 commits into
nushell:mainfrom
casedami:feat-abbreviations

Conversation

@casedami
Copy link
Copy Markdown
Contributor

@casedami casedami commented May 13, 2026

Description

Adds support for fish-style abbreviations that are expanded on enter or space. Add them to your config like so:

$env.config.abbreviations = {
  ll: "ls -l",
  gs: "git status"
}

User-facing changes (Release notes)

Added support for fish-style abbreviations that are expanded on enter or space. Abbreviations are syntax-aware in that expansion doesn't occur within strings or when appearing as arguments to an external program.

Abbreviations can be added to the config like so:

$env.config.abbreviations = {
  ll: "ls -l"
  gs: "git status"
}

Also added abbr and abbr list commands to help make this functionality more discoverable.

Additional notes

supports this reedline feature nushell/reedline#1060

@github-actions
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.

@casedami casedami marked this pull request as draft May 13, 2026 17:24
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 13, 2026

Thanks @casedami. I'm not sure this is how we want it to work exactly.

Added a conversation on Discord https://discord.com/channels/601130461678272522/615329862395101194/1504176644804579409

How should this feature work?

  1. The way it is now, with a hashmap in config (maybe a nushell record)
  2. Use a nushell list in the config
  3. Point to a file that has a list of abbreviations
  4. Add a built-in command like abbr ll ls -al and just call it a doze times for a dozen abbreviations
  5. other ideas?

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 14, 2026

After yesterday's team meeting we decided on 3 things regarding this PR.

  1. The list of abbreviations should be a nushell record in the config.nu
  2. We should not have a built-in command like abbr at this point because that would infer that abbreviations work in scripts, which is not the case. They're for the repl only.
  3. You should be able to modify the abbreviations at runtime in the repl with $env.config.abbreviations =

If we can get the CI green and make sure these items are followed, we can land this PR.

@casedami
Copy link
Copy Markdown
Contributor Author

Ok sounds good, I'll start working on that

@casedami
Copy link
Copy Markdown
Contributor Author

casedami commented May 15, 2026

waiting on nushell/reedline#1074

tried my hand at this, not sure what y'all think of it. currently highlight only writes to the cache it doesnt actually use it to backout early which im not sure how important that is but i think it would require saving some more stuff in the cache to do that.

also havent tested it yet until im able to update reedline with the linked pr

@fdncred @blindFS

@blindFS
Copy link
Copy Markdown
Contributor

blindFS commented May 15, 2026

LGTM at first glance, thanks!

I'm not sure what you mean by backout early, if you find something to optimize in the highlighter, feel free to draft another issue/PR.

BTW I assume the highlighting given the same input always happens before the string literal check. If not the case, we might need to do some adjustments.

@casedami
Copy link
Copy Markdown
Contributor Author

casedami commented May 15, 2026

By backout early i meant a way to somehow use the cache inside highlight_syntax but i'm not as confident about being able to do that so that kind of optimization is probably not something to consider right now.

as far as i understand, the highlighting always happens before the string literal check

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 16, 2026

waiting on nushell/reedline#1074

landed!

@casedami casedami marked this pull request as ready for review May 16, 2026 03:24
@casedami
Copy link
Copy Markdown
Contributor Author

One note: expansion still occurs inside a string literal for FlatShape::ExternalArg, for example

$env.config.abbreviations = { gs: "git status" }
bash -c "echo gs ..." # gs would expand here

this seems like something that would be maybe unexpected for a user? i could add another check within is_inside_string_literal that returns false if the shape is ExternalArg to prevent this

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 16, 2026

i could add another check within is_inside_string_literal that returns false if the shape is ExternalArg to prevent this

Ya, seems appropriate to do that. I agree that would be surprising and we should eliminate that if we can.

@casedami
Copy link
Copy Markdown
Contributor Author

casedami commented May 16, 2026

Last thing, i had originally added support for abbreviations list but this is functionally the same as $env.config.abbreviations. Do you want me to remove the abbreviation list command? Especially because you can add abbreviations with something like $env.config.abbreviations = $env.config.abbreviations | insert hi hello whereas the existence of abbreviations list gives the impression that there might be an abbreviation add command or something similar

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 16, 2026

I'm fine either way. In one respect it's more discoverable because you can do help -f abbr and find the command.

@casedami
Copy link
Copy Markdown
Contributor Author

Assuming this make CI go green, should be all set unless there are any other concerns/comments

@casedami casedami changed the title Feat: fish-style abbreviations feat: fish-style abbreviations May 16, 2026
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 20, 2026

I wonder if it's a problem that if you have an abbreviation like la and you just want to run it, you have to hit enter twice or space then enter. Seems like if you hit enter it would just expand and run the expansion. Thoughts?

@casedami
Copy link
Copy Markdown
Contributor Author

thats probably more intuitive i agree, to do that would be a simple change to reedline. i can submit a PR for that

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 21, 2026

ok, i landed your reedline pr this morning. is there things to implement here too or just update the reedline commit in cargo.toml?

@casedami
Copy link
Copy Markdown
Contributor Author

Just need to update reedline, I can do it in the next hour or so but if you'd rather get it done then feel free

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 21, 2026

ok, i'll do it. i have a couple other things i want to change too.

@fdncred fdncred merged commit 062e299 into nushell:main May 21, 2026
19 checks passed
@github-actions github-actions Bot added this to the v0.113.0 milestone May 21, 2026
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 21, 2026

Thanks for all of this!

@casedami
Copy link
Copy Markdown
Contributor Author

Thanks for your help and feedback!

@casedami casedami deleted the feat-abbreviations branch May 21, 2026 15:54
@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section A:alias Issues around support for command aliases, touches parser and name resolution labels May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:alias Issues around support for command aliases, touches parser and name resolution notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants