Skip to content

Let an alias end with a flag that takes a value - #19623

Merged
fdncred merged 1 commit into
nushell:mainfrom
fdncred:alias_flag_value
Nov 21, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
fdncred:alias_flag_value

Conversation

@fdncred

@fdncred fdncred commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Description

alias myfind = find -r was accepted, but myfind "txt$" searched for the literal text txt$ and returned an empty list with no error. The alias kept -r without a value, so the next word went to find's other parameters.

Now the first word after such an alias becomes the flag's value, the way bash, zsh and fish expand aliases. If no word follows, the parser reports the missing value at the alias name. --help and -h still show help, and tab completion after the alias offers the flag's values.

Names in the alias still resolve where it's defined, so alias ls = ls -a still doesn't call itself.

Examples, main against this branch.

These work now:

Code main this branch
alias myfind = find -r; ["file.txt" "x"] | myfind "txt$" empty list [file.txt]
alias myfind = find -r; ["FILE.TXT" "x"] | myfind "txt$" -i empty list [FILE.TXT]
alias hex = into int --radix; "ff" | hex 16 error: Data cannot be accessed with a cell path 255
alias j = to json -i; {a: 1} | j 4 error: Extra positional argument JSON indented by 4 spaces

These don't change:

Code main this branch
extern "/bin/echo" [--foo: string, ...rest: string]; alias e = /bin/echo --foo; e bar --foo bar --foo bar
alias rep = str replace -a; "aaa" | rep a b bbb bbb
alias myfind = find -r; [] | myfind --help help for find help for find
alias myfind = find -r; [] | myfind -h help for find help for find

These are now an error, the same one you get typing the expansion alone:

Code main this branch
alias j = to json -i; {a: 1} | j JSON indented by 2 spaces error: Missing flag argument
alias myfind = find -r; ["file.txt"] | myfind error: Missing parameter: search term or --regex error: Missing flag argument
extern "/bin/echo" [--foo: string, ...rest: string]; alias e = /bin/echo --foo; e --foo error: Missing flag argument
def cmd [--opt: any] { $opt }; alias c = cmd --opt; c true error: Missing flag argument

User-facing changes (Release notes)

  • An alias that ends with a flag that takes a value now takes the value from the first word after it. With alias myfind = find -r, myfind "txt$" runs find -r "txt$". Before, the flag got no value and the alias could return wrong results with no error.
  • Breaking change. Using such an alias with nothing after it is now a "Missing flag argument" error, as typing its expansion alone already was. This includes aliases of commands declared with extern.

Breaking Changes

1. Using the alias with nothing after it is now a parse error

alias j = to json -i
{a: 1} | j
  • Before: it runs and ignores -i, so you get the default 2-space indent.
  • After: MissingFlagParam, pointing at j.

Because it fails at parse time, a config.nu or module that uses such an alias this way anywhere now fails to load, not just that one line. The memory note for this branch already records this as the intended break.

2. The first word after the alias now goes to the flag instead of to the positional arguments

def cmd [--opt: string, ...rest] { {opt: $opt, rest: $rest} }
alias c = cmd --opt
c x y
  • Before: {opt: true, rest: [x, y]}. A string flag got the boolean true.
  • After: {opt: x, rest: [y]}.

If the flag is typed int, the same call used to run with opt: true. Now x fails the type check as a parse error.

Additional notes

`alias myfind = find -r` stored `-r` without a value, so `myfind "txt$"`
passed `txt$` to find's other parameters and returned an empty list with
no error. The first word after such an alias now becomes the flag's
value, and a bare use reports the missing value at the alias name.
`--help` and `-h` after the alias still show help.

The filled flag's name gets an empty span where its value starts, so
argument spans and error labels stay at the use site even when the alias
is defined in config.nu. Flatten skips flags with empty name spans.

Reported in nushell#19616 (comment)
@github-actions github-actions Bot added the A:parser Issues related to parsing label Nov 20, 2026
@fdncred

fdncred commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@zozo123 any ideas what's going on with ci now?

@fdncred fdncred added notes:breaking-changes Noted in Breaking Changes section notes:ready Indicates Ready for Release notes labels Nov 21, 2026
@fdncred
fdncred merged commit bc405a2 into nushell:main Nov 21, 2026
23 of 29 checks passed
@fdncred
fdncred deleted the alias_flag_value branch November 21, 2026 13:15
@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 21, 2026
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 notes:breaking-changes Noted in Breaking Changes section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant