Skip to content

Allow escaping glob with \ in nu-glob - #10246

Closed
horasal wants to merge 8 commits into
nushell:mainfrom
horasal:escape_glob
Closed

horasal wants to merge 8 commits into
nushell:mainfrom
horasal:escape_glob

Conversation

@horasal

@horasal horasal commented Sep 5, 2023 •

Copy link
Copy Markdown
Contributor

Related: #10244

Description

  1. Current nu-glob only escape glob chars with [], this pr also allows \ to escape them. e.g.

    ls \*   # list folder `*`
    ls \?  # list folder `?`
    ls \[test\]  # list folder `[test]`

    and user can still use [[], [*] to escape glob chars.

  2. ls is more consistent for folder with glob chars, e.g.

    mkdir *
    ls *  # now with list all files under current folder
    ls \* # only list fold `*`

User-Facing Changes

User can use either to escape '[', '*', '?':

  • ls \[test\]
  • ls [[]test[]]

Notice: In current implementation, \ need to be escaped ONLY when used with glob, for example

This is a glob, so it should be escaped:

escape

But this is not, it's just a raw path string, no \ does not need to be escaped:

raw path

Should \ always need to be escaped?

Tests + Formatting

  • 🟢 toolkit fmt
  • 🟢 toolkit clippy
  • 🟢 toolkit test
  • 🟢 toolkit test stdlib

After Submitting

As mentioned in #10244, it'll be better to have some documentation about how to use nu-glob.

@horasal
horasal marked this pull request as draft September 5, 2023 23:58
@horasal

horasal commented Sep 6, 2023 •

Copy link
Copy Markdown
Contributor Author

hmm, \ causes bunch of problems on Windows. I don't really think it worthes to change more(the way nushell handle string/escape, path handling in both ls/glob_from and maybe path expansion) just for this.

I'll file another pr for fa11fb8 and close this.

@fdncred

fdncred commented Sep 6, 2023

Copy link
Copy Markdown
Contributor

Trying to get Windows to work right is always the problem because you can have things like C:\Program Files\Some Folder. What makes it worse is that when you use double quotes, it interprets escapes, so in this example, if it were in double quotes, \P and \S would try to be interpreted as escapes. To make it more complicated, when there are spaces in the path, we need to use backtick quotes.

@amtoine

amtoine commented Sep 6, 2023

Copy link
Copy Markdown
Member

not sure about #9310 entirely, just wanted to not forget about it 👍

sholderbach added a commit that referenced this pull request Sep 29, 2023
# Description
This merges @horasal 's changes from #10246 and #10269

Closes #10205
Closes #8714

Fixes the bug that editor paths with spaces are unusable

Closes #10210 
Closes #10269


# User-Facing Changes
You can now either pass a string with the name of the executable or a
list with the executable and any flags to
`$env.config.buffer_editor`/`$env.EDITOR`/`$env.VISUAL`

Both the external buffer editor of reedline (by default bound to
`Ctrl-o`) and the commands `config nu` and `config env` will respect
those variables in the following order:
1. `$env.config.buffer_editor`
2. `$env.EDITOR`
3. `$env.VISUAL`

Example:
```
$env.EDITOR = "nvim"                      # The system-wide EDITOR is neovim
$env.config.buffer_editor = ["vim" "-p2"] # Force vim to open two tabs (not particularly useful)
$env.config.buffer_editor = null          # Unset `buffer_editor` -> Uses `$env.EDITOR` ergo nvim
```
# Tests + Formatting
None

---------

Co-authored-by: Horasal <[email protected]>
@horasal

horasal commented Oct 13, 2023

Copy link
Copy Markdown
Contributor Author

close this as many better approaches are proposed and being discussed:

#10364
#10694
#10651

@horasal horasal closed this Oct 13, 2023
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
# Description
This merges @horasal 's changes from nushell#10246 and nushell#10269

Closes nushell#10205
Closes nushell#8714

Fixes the bug that editor paths with spaces are unusable

Closes nushell#10210 
Closes nushell#10269


# User-Facing Changes
You can now either pass a string with the name of the executable or a
list with the executable and any flags to
`$env.config.buffer_editor`/`$env.EDITOR`/`$env.VISUAL`

Both the external buffer editor of reedline (by default bound to
`Ctrl-o`) and the commands `config nu` and `config env` will respect
those variables in the following order:
1. `$env.config.buffer_editor`
2. `$env.EDITOR`
3. `$env.VISUAL`

Example:
```
$env.EDITOR = "nvim"                      # The system-wide EDITOR is neovim
$env.config.buffer_editor = ["vim" "-p2"] # Force vim to open two tabs (not particularly useful)
$env.config.buffer_editor = null          # Unset `buffer_editor` -> Uses `$env.EDITOR` ergo nvim
```
# Tests + Formatting
None

---------

Co-authored-by: Horasal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filenames with square brackets cause errors Error on the commands 'cp', 'mv', 'rm', and 'open' on files that have [ ] on its path

3 participants