Repository navigation
Description
Basics
- I have done a basic search through the issue tracker to find similar or related issues.
- I have made myself familiar with the available features of Nushell for the particular area this enhancement request touches.
Related problem
Motivation:
allow us to create wrapper commands with the builtin sigil %, using parameterized variables like ($arg1)
% sigil should support dynamic dispatch via %($var), like ^($var) does for externals
The ^ and % sigils are conceptual mirrors -- one forces external resolution, the other forces built-in resolution. But ^ supports dynamic dispatch via variables while % does not.
This works:
export def --wrapped command [arg1, ...args] { ^($arg1) ...$args }This gives a parse error:
export def --wrapped builtin [arg1, ...args] { %($arg1) ...$args }
Error: nu::parser::error
× percent sigil requires a built-in command
╭─[/path/to/my/file.nu:28:51]
27 │ export def --wrapped command [arg1, ...args] { ^($arg1) ...$args }
28 │ export def --wrapped builtin [arg1, ...args] { %($arg1) ...$args }
· ───┬───
· ╰── unknown built-in command
╰────
help: remove `%` to use normal resolution, or use `^` to run an external command explicitlyThe two definitions are structurally identical -- only the sigil differs. ^($arg1) defers resolution to runtime. %($arg1) fails at parse time.
- PR add a new sigil
%for built-ins like^is a sigil for externals #17956 introduced %. PR fix issue with sigil recursion #18084 fixed a recursion bug when using % inside a same-named wrapper. - The motivating use case is to allow us to create wrapper commands with the builtin sigil
%, using stuff like($arg1)
Describe the solution you'd like
Support %($var) syntax for dynamic dispatch of built-in commands at runtime, matching the existing ^($var) behavior for externals.
The parser would need to defer validation of the command name to runtime when the argument to % is an expression (variable, subexpression, etc.) rather than a literal. At runtime, if the resolved name is not a known built-in, a runtime error would be raised -- the same approach ^($var) takes when the external binary doesn't exist.
This would enable the command/builtin pair to work symmetrically:
export def --wrapped command [arg1, ...args] { ^($arg1) ...$args } # bypass aliases, functions, builtins
export def --wrapped builtin [arg1, ...args] { %($arg1) ...$args } # bypass aliases, functions, externalsDescribe alternatives you've considered
Describe alternatives you've considered:
- Manual match/enumeration: Enumerate every built-in in a
matchblock. Fragile, verbose, breaks when new built-ins are added.
Additional context and details
No response
Activity
[-]Title: % builtin sigil should support dynamic dispatch via %($var), like ^($var) does for externals, allowing us to create parameterized wrapper commands[/-][+]allow us to create wrapper commands with the builtin sigil %, using parameterized variables like ($arg1)[/+]fdncred commentedon May 2, 2026
Seems reasonable. All it takes is someone submitting a PR that fixes it.
fdncred commentedon May 4, 2026
You might want to try #18158 and see if it addresses your issue.
i-api commentedon May 5, 2026
@fdncred thanks for the help
I tested it out and it mostly works, one thing I noticed is that the fix can't handle ...$rest_style_arguments, so this fails:
so I added a commit on top of your fix to address that
link: https://github.com/i-api/nushell/tree/fdncred/dynamic_percent_cmds
I'll submit a PR to your branch and to the upstream, feel free to use either
i-api commentedon May 5, 2026
@fdncred Here is the PR link to your branch: fdncred#9
fdncred commentedon May 5, 2026
@i-api Thanks. I've updated the PR. Please try again.
i-api commentedon May 5, 2026
@fdncred thanks for the help. I tested it.
We'd need to handle the case for commands which have a default behavior when no arguments are passed in, e.g. nushell's "ls" command;
i-api commentedon May 5, 2026
@fdncred here is the external equivalent, which does behave as expected
i-api commentedon May 5, 2026
@fdncred Thanks for your help on this so far, much appreciated
fdncred commentedon May 5, 2026
Thanks. I'll look into this.
fdncred commentedon May 5, 2026
@i-api One more try? I pushed a new commit that hopefully covers this case too.
i-api commentedon May 5, 2026
@fdncred tested it, it works :) Thank you 👍
fdncred commentedon May 5, 2026
@i-api Any other concerns or tests you want to perform or should we land the PR an see what happens?
i-api commentedon May 5, 2026
@fdncred lets land the PR 👍
implement dynamic dispatch for % sigil commands (#18158)