Skip to content

glob command supports more metacharacters than filesystem commands like cp and mv #10498

@bobhy

Description

@bobhy

Describe the bug

It looks like only the glob command supports the the csh-style `{}' metacharacters, the file utilities do not.

You could argue this is more of an enhancement request, but I think globbing is so fundamental a shell experience that it must be consistent across use cases.

How to reproduce

> touch a.foo a.bar
> ls
╭───┬───────┬──────┬──────┬──────────╮
│ # │ name  │ type │ size │ modified │
├───┼───────┼──────┼──────┼──────────┤
│ 0 │ a.bar │ file │  0 B │ now      │
│ 1 │ a.foo │ file │  0 B │ now      │
╰───┴───────┴──────┴──────┴──────────╯
> glob a.{foo,bar}
╭───┬────────────────────────────────────╮
│ 0 │ /home/bobhy/src/rust/work/r3/a.bar │
│ 1 │ /home/bobhy/src/rust/work/r3/a.foo │
╰───┴────────────────────────────────────╯

So glob supports {}. Great!

> mkdir dir_a
> cp a.{foo,bar} dir_a
Error:   × No matches found
   ╭─[entry #187:1:1]
 1 │ cp a.{foo,bar} dir_a
   ·    ─────┬─────
   ·         ╰── no matches found
   ╰────

> ucp a.{foo,bar} dir_a
Error: nu::shell::file_not_found

  × File not found
   ╭─[entry #188:1:1]
 1 │ ucp a.{foo,bar} dir_a
   ·     ─────┬─────
   ·          ╰── file not found
   ╰────

cp and ucp do not. Not shown here, but neither do rm, mv, touch .

Expected behavior

I'd really like all Nu globbing to support '{}' metacharacters.

Screenshots

No response

Configuration

key value
version 0.85.1
branch main
commit_hash 95a4649
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.70.0 (90c541806 2023-05-31)
rust_channel 1.70.0-x86_64-unknown-linux-gnu
cargo_version cargo 1.70.0 (ec8a8a0ca 2023-04-25)
build_time 2023-09-24 10:42:53 -07:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash, which, zip
installed_plugins

Additional context

Looking at the code, the filesystem utilities use crates/nu-glob, but glob uses wax::Glob.

Understood, I could do:

glob a.{foo,bar} | each {|p| cp $p dir_a}

with a minor loss of efficiency. But that's just papering over the crack...

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:file-systemRelated to commands and core nushell behavior around the file systemA:globBehavior around file-system globbing with regular commands or `glob`. See also A:quoting/expansionstatus:needs-triageAn issue that hasn't had any proper look

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions