Skip to content

allow us to create wrapper commands with the builtin sigil %, using parameterized variables like ($arg1) #18150

Closed

Description

@i-api

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 explicitly

The two definitions are structurally identical -- only the sigil differs. ^($arg1) defers resolution to runtime. %($arg1) fails at parse time.

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, externals

Describe alternatives you've considered

Describe alternatives you've considered:

  • Manual match/enumeration: Enumerate every built-in in a match block. Fragile, verbose, breaks when new built-ins are added.

Additional context and details

No response

Activity

  1. added
    category:enhancement
    status:needs-triage
    on May 2, 2026
  2. changed the title [-]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)[/+] on May 2, 2026
  3. fdncred commented on May 2, 2026

    @fdncred
    Contributor

    Seems reasonable. All it takes is someone submitting a PR that fixes it.

  4. fdncred commented on May 4, 2026

    @fdncred
    Contributor

    You might want to try #18158 and see if it addresses your issue.

  5. i-api commented on May 5, 2026

    @i-api
    ContributorAuthor

    @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:

    export def --wrapped builtin [arg1, ...args]   { %($arg1) ...$args } 
    builtin ls 
    Error: nu::shell::io::not_found
     Not found
       ╭─[repl_entry #1:1:59]
     1 │ export def --wrapped builtin [arg1, ...args]   { %($arg1) ...$args }
       ·                                                           ────┬───
       ·                                                               ╰── Not found
       ╰────
      help: '/Users/me/Downloads/nushell/...$args' does not exist

    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

  6. i-api commented on May 5, 2026

    @i-api
    ContributorAuthor

    @fdncred Here is the PR link to your branch: fdncred#9

  7. fdncred commented on May 5, 2026

    @fdncred
    Contributor

    @i-api Thanks. I've updated the PR. Please try again.

  8. i-api commented on May 5, 2026

    @i-api
    ContributorAuthor

    @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;

    > export def --wrapped builtin [arg1, ...args]   { %($arg1) ...$args }
    > builtin ls          # This does not work
    ╭────────────╮
    │ empty list │
    ╰────────────╯
    > builtin ls .        # This works 
    ╭────┬─────────────────────┬─────────┬──────────┬────────────╮
    │  # │        name         │  type   │   size   │  modified  │
    ├────┼─────────────────────┼─────────┼──────────┼────────────┤
    │  0 │ AGENTS.md           │ file    │   2.0 kB │ 2026-04-24 │
    │  1 │ CITATION.cff        │ file    │    812 B │ 2026-04-24 │
    │  2 │ CLAUDE.md           │ symlink │      9 B │ 2026-04-24 │
    │  3 │ CODE_OF_CONDUCT.md  │ file    │   3.4 kB │ 2026-04-24 │
    │  4 │ CONTRIBUTING.md     │ file    │  18.3 kB │ 2026-04-24 │
    │  5 │ Cargo.lock          │ file    │ 246.9 kB │ 2026-04-24 │
    │  6 │ Cargo.toml          │ file    │  11.5 kB │ 2026-04-24 │
    │  7 │ Cross.toml          │ file    │    666 B │ 2026-04-24 │
    │  8 │ LICENSE             │ file    │   1.0 kB │ 2026-04-24 │
    │  9 │ README.md           │ file    │  12.5 kB │ 2026-04-24 │
    │ 10 │ SECURITY.md         │ file    │   2.6 kB │ 2026-04-24 │
    │ 11 │ assets              │ dir     │    160 B │ 2026-04-24 │
    │ 12 │ ast-grep            │ dir     │    160 B │ 2026-04-24 │
    │ 13 │ benches             │ dir     │    128 B │ 2026-04-24 │
    │ 14 │ clippy.toml         │ file    │    164 B │ 2026-04-24 │
    │ 15 │ crates              │ dir     │   1.4 kB │ 2026-04-24 │
    │ 16 │ devdocs             │ dir     │    256 B │ 2026-04-24 │
    │ 17 │ docker              │ dir     │    160 B │ 2026-04-24 │
    │ 18 │ rust-toolchain.toml │ file    │    939 B │ 2026-04-24 │
    │ 19 │ rustfmt.toml        │ file    │     17 B │ 2026-04-24 │
    │ 20 │ scripts             │ dir     │    448 B │ 2026-04-24 │
    │ 21 │ sgconfig.yml        │ file    │    210 B │ 2026-04-24 │
    │ 22 │ src                 │ dir     │    448 B │ 2026-04-24 │
    │ 23 │ target              │ dir     │    160 B │ 2026-05-05 │
    │ 24 │ tests               │ dir     │    576 B │ 2026-04-24 │
    │ 25 │ toolkit             │ dir     │    384 B │ 2026-04-24 │
    │ 26 │ toolkit.nu          │ file    │     58 B │ 2026-04-24 │
    │ 27 │ typos.toml          │ file    │    708 B │ 2026-04-24 │
    │ 28 │ wix                 │ dir     │    224 B │ 2026-04-24 │
    ├────┼─────────────────────┼─────────┼──────────┼────────────┤
    │  # │        name         │  type   │   size   │  modified  │
    
    
  9. i-api commented on May 5, 2026

    @i-api
    ContributorAuthor

    @fdncred here is the external equivalent, which does behave as expected

    > export def --wrapped command [arg1, ...args]   { ^($arg1) ...$args }
    > command ls  # this works as expected
    AGENTS.md           Cargo.lock          clippy.toml         Cross.toml          README.md           SECURITY.md         tests               wix
    assets              Cargo.toml          CODE_OF_CONDUCT.md  devdocs             rust-toolchain.toml sgconfig.yml        toolkit
    ast-grep            CITATION.cff        CONTRIBUTING.md     docker              rustfmt.toml        src                 toolkit.nu
    benches             CLAUDE.md           crates              LICENSE             scripts             target              typos.toml
    > command ls . # this works as expected
    AGENTS.md           Cargo.lock          clippy.toml         Cross.toml          README.md           SECURITY.md         tests               wix
    assets              Cargo.toml          CODE_OF_CONDUCT.md  devdocs             rust-toolchain.toml sgconfig.yml        toolkit
    ast-grep            CITATION.cff        CONTRIBUTING.md     docker              rustfmt.toml        src                 toolkit.nu
    benches             CLAUDE.md           crates              LICENSE             scripts             target              typos.toml
    >
    
  10. i-api commented on May 5, 2026

    @i-api
    ContributorAuthor

    @fdncred Thanks for your help on this so far, much appreciated

  11. fdncred commented on May 5, 2026

    @fdncred
    Contributor

    @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;

    > export def --wrapped builtin [arg1, ...args]   { %($arg1) ...$args }
    > builtin ls          # This does not work
    ╭────────────╮
    │ empty list │
    ╰────────────╯
    > builtin ls .        # This works 
    ╭────┬─────────────────────┬─────────┬──────────┬────────────╮
    │  # │        name         │  type   │   size   │  modified  │
    ├────┼─────────────────────┼─────────┼──────────┼────────────┤
    │  0 │ AGENTS.md           │ file    │   2.0 kB │ 2026-04-24 │
    │  1 │ CITATION.cff        │ file    │    812 B │ 2026-04-24 │
    │  2 │ CLAUDE.md           │ symlink │      9 B │ 2026-04-24 │
    

    Thanks. I'll look into this.

  12. fdncred commented on May 5, 2026

    @fdncred
    Contributor

    @i-api One more try? I pushed a new commit that hopefully covers this case too.

  13. i-api commented on May 5, 2026

    @i-api
    ContributorAuthor

    @fdncred tested it, it works :) Thank you 👍

  14. fdncred commented on May 5, 2026

    @fdncred
    Contributor

    @i-api Any other concerns or tests you want to perform or should we land the PR an see what happens?

  15. i-api commented on May 5, 2026

    @i-api
    ContributorAuthor

    @fdncred lets land the PR 👍

  16. added this to the v0.113.0 milestone on May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:enhancementstatus:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions