Skip to content

Addition of the Abbreviation#16960

Open
philocalyst wants to merge 6 commits intonushell:mainfrom
philocalyst:command_abbr
Open

Addition of the Abbreviation#16960
philocalyst wants to merge 6 commits intonushell:mainfrom
philocalyst:command_abbr

Conversation

@philocalyst
Copy link

@philocalyst philocalyst commented Nov 1, 2025

Release notes summary - What our users need to know

MY NOTES:

  • I didn't know where to implement the actual command logic so this PR currently only contains the parsing of the abbreviation command. I don't know what else is needed beyond that, but it's almost entirely based upon the alias command, so it should work as well as the alias command does.
  • I would like to add the actual core logic
  • Should I add tests? How many and what scope should they cover?
  • Should resolve Any way to expand alias? #5552 fish-like abbreviations #5597

Tasks after submitting

@github-actions github-actions bot added the A:parser Issues related to parsing label Nov 1, 2025
@blindFS
Copy link
Contributor

blindFS commented Nov 1, 2025

If the implementation is that similar to alias, why not make it an argument of alias command?

@philocalyst
Copy link
Author

That's a great question, I was just using fish as a reference point, which has two separate commands.

Alias is syntax sugar for a one-line function more or less, while abbreviation exhibits a more feature set which allows you to be as precise as you'd like to be for when it's actually triggered. The approach that nushell could take is that alias is overloaded to support "inline replacement", and then bring in the rest of these advanced matching arguments?

I could see that as being useful as more idiomatic command builder, where you could define an alias that replaces different things based on the host system for example? But maybe that's a pattern we don't want?

@fdncred
Copy link
Contributor

fdncred commented Dec 4, 2025

@NotTheDr01ds reminded me that if you're looking for abbreviation expansion, nushell can do already that if setup properly.
https://www.nushell.sh/blog/2024-05-15-top-nushell-hacks.html

@philocalyst
Copy link
Author

philocalyst commented Dec 5, 2025

Of course it can! Nushell is very robust, and can emulate a lot with some tinkering, including the emulation of a number of other builtins; So I don't think it's a reason to not move forward.

@fdncred
Copy link
Contributor

fdncred commented Dec 5, 2025

I'm struggling to understand the value with this command and that's not a criticism of your hard work here. I know fish has abbr's and aliases, but I never really used abbr's much. Why is this an important feature that nushell should have?

@philocalyst
Copy link
Author

philocalyst commented Dec 6, 2025 via email

@fdncred
Copy link
Contributor

fdncred commented Dec 6, 2025

I'd personally push for these type of changes built into aliases. Aliases need some work (jus search the issues) and it would be nice to clean them up a bit too. Maybe that's something you can help with while adding the abbr features to alias?

@cybardev
Copy link

re: #16960 (comment)

Thanks for the blog link, @fdncred . Do you happen to know how abbrs can be set up to expand on Space instead of Ctrl+Space?

@fdncred
Copy link
Contributor

fdncred commented Dec 18, 2025

you could try setting the modifier to none i think

@cybardev
Copy link

$env.config.keybindings ++= [{
  name: abbr
  modifier: none
  keycode: space
  mode: [emacs, vi_insert]
  event: [
    { send: menu name: abbr_menu }
    { edit: insertchar, value: ' '}
  ]
}]

Added this to the config file, but it's still not similar to fish (e.g. gcm<Space> -> git commit -m). 😓

@fdncred
Copy link
Contributor

fdncred commented Dec 19, 2025

No one said it worked like fish. If you use the aliases in nu_scripts you'll see what gcm is there.
https://github.com/nushell/nu_scripts/blob/4af008a317185b4e247bdb13002dbc074e98b60c/aliases/git/git-aliases.nu#L73

@cybardev
Copy link

cybardev commented Dec 19, 2025

@fdncred I didn't actually try it with gcm (I said it as an example) but with my custom aliases set in the config file. I also didn't have nu_scripts installed (was not aware it existed, but looks useful; thanks). Regardless, here's what I get if I set fish's abbreviation to be the same as the nushell alias you linked:

  • in fish:
    gcm<Space> -> git checkout main (it expands)
  • in nushell (with modifier none as mentioned above):
    gcm<Space> -> gcm (it doesn't expand, just puts a literal space)

Basically, I don't need the aliases to mean the same thing as in fish. I just want Space to expand the aliases I define instead of needing a modifier.


EDIT: I think it'd be better not to pollute the PR so I will move my question to a Discussion. Thanks for your help.
UPDATE: There already exists a discussion regarding what I want: #2936

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

Labels

A:parser Issues related to parsing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Any way to expand alias?

4 participants