Skip to content

add str escape-glob command#11664

Merged
WindSoilder merged 3 commits intonushell:mainfrom
WindSoilder:escape_glob
Jan 29, 2024
Merged

add str escape-glob command#11664
WindSoilder merged 3 commits intonushell:mainfrom
WindSoilder:escape_glob

Conversation

@WindSoilder
Copy link
Copy Markdown
Contributor

Description

This pr is a follow up to #11621, it introduces a str escape-glob command as a workaround for the case:

let f = "a[123]b"
ls $f

It will glob a[123]b, we can get rid of the behavior through str escape-glob command:

let f = "a[123]b"
ls ($f | str escape-glob)

It's more useful in the each context:
ls | get name | str escape-glob | each {|it| ls $it}

User-Facing Changes

NaN

Tests + Formatting

Done

After Submitting

Copy link
Copy Markdown
Contributor

@fdncred fdncred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for the one minor thing in the example, I think this is an interesting approach.

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Jan 29, 2024

This kind of works

 ls test* | get name | str escape-glob | each {|it| ls -D $it} | flatten  
╭─#─┬──name───┬─type─┬─size──┬───modified────╮
 0  test[a]  file    0 B  3 minutes ago 
 1  tests    dir   480 B  2 days ago    
╰───┴─────────┴──────┴───────┴───────────────╯

but this shows a different result.

 touch "test[a]"
 ls test* | $in.name | str escape-glob 
╭───┬─────────────╮
 0  test[[]a[]] 
 1  tests       
╰───┴─────────────╯

I'm not sure if that's intended or not?

@WindSoilder
Copy link
Copy Markdown
Contributor Author

I think it's intended, it shows escaped result. And that's why it works in the first case you provided.

@WindSoilder WindSoilder merged commit 0e023ea into nushell:main Jan 29, 2024
@WindSoilder WindSoilder deleted the escape_glob branch January 29, 2024 15:00
@hustcer hustcer added this to the v0.90.0 milestone Feb 3, 2024
@kubouch kubouch added the deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way label Feb 4, 2024
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description
This pr is a follow up to nushell#11621, it introduces a `str escape-glob`
command as a workaround for the case:

```nushell
let f = "a[123]b"
ls $f
```

It will glob `a[123]b`, we can get rid of the behavior through `str
escape-glob` command:

```nushll
let f = "a[123]b"
ls ($f | str escape-glob)
```

It's more useful in the `each` context:
`ls | get name | str escape-glob | each {|it| ls $it}`

# User-Facing Changes
NaN

# Tests + Formatting
Done

# After Submitting

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
@fdncred fdncred added the A:glob Behavior around file-system globbing with regular commands or `glob`. See also A:quoting/expansion label Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:glob Behavior around file-system globbing with regular commands or `glob`. See also A:quoting/expansion deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants