open, rm, umv, cp, rm and du: Don't globs if inputs are variables or string interpolation#11886
Conversation
|
I think it is a good change to remove auto-globbing from variables and string interpolations. Also agreed that we can get rid of I'm just not sold on adding First, custom commands: Note: Second, externals. Currently, we do expand globs for externals: If we remove the variable/string interp. auto-globbing (which we should), there would be no way to allow it for externals because we can't add a Third, plugins? Any other cases? I am thinking of three alternatives (not mutually exclusive):
We have two other features related to globbing: |
|
A much more radical approach to number 2 of @kubouch's comments above is to remove globbing from every command and only allow globs via the glob command and the used with the spread operator. It could cause people to lose their mind, but it would simplify things. (maybe remove it from all commands except I'm up for giving most anything a try in order to get something nushell-y that we love. |
We can fell into trouble if user uses Personally I like 2nd and 3rd solution :) Although I'm not sure how to make it works with |
|
How does this perform with Kubouch's glob torture tests? BTW, I put it here so we can make changes to it easily https://hackmd.io/y5yMvEnrR7WTLH3vVBQlFg?edit |
|
|
|
I still fail into a trouble to play with the following two cases, given two files:
Not really sure if the behavior is ok Edit: the 2nd is resolved. There is only 1st issue left, but sadly I don't think there is a solution. |
|
Reply to @kubouch 's proposal:
Done :)
Nushell supports this feature on most of filesystem command except
Currently this pr doesn't implement it. We can do this by |
|
I think we can land and iterate through it |
|
go for it, if you think it's ready. |
That's a fantastic solution to the problem, thanks! |
…ariables or string interpolation (nushell#11886) # Description This is a follow up to nushell#11621 (comment) Also Fixes: nushell#11838 ## About the code change It applys the same logic when we pass variables to external commands: https://github.com/nushell/nushell/blob/0487e9ffcbc57c2d5feca606e10c3f8221ff5e00/crates/nu-command/src/system/run_external.rs#L162-L170 That is: if user input dynamic things(like variables, sub-expression, or string interpolation), it returns a quoted `NuPath`, then user input won't be globbed # User-Facing Changes Given two input files: `a*c.txt`, `abc.txt` * `let f = "a*c.txt"; rm $f` will remove one file: `a*c.txt`. ~* `let f = "a*c.txt"; rm --glob $f` will remove `a*c.txt` and `abc.txt`~ * `let f: glob = "a*c.txt"; rm $f` will remove `a*c.txt` and `abc.txt` ## Rules about globbing with *variable* Given two files: `a*c.txt`, `abc.txt` | Cmd Type | example | Result | | ----- | ------------------ | ------ | | builtin | let f = "a*c.txt"; rm $f | remove `a*c.txt` | | builtin | let f: glob = "a*c.txt"; rm $f | remove `a*c.txt` and `abc.txt` | builtin | let f = "a*c.txt"; rm ($f \| into glob) | remove `a*c.txt` and `abc.txt` | custom | def crm [f: glob] { rm $f }; let f = "a*c.txt"; crm $f | remove `a*c.txt` and `abc.txt` | custom | def crm [f: glob] { rm ($f \| into string) }; let f = "a*c.txt"; crm $f | remove `a*c.txt` | custom | def crm [f: string] { rm $f }; let f = "a*c.txt"; crm $f | remove `a*c.txt` | custom | def crm [f: string] { rm $f }; let f = "a*c.txt"; crm ($f \| into glob) | remove `a*c.txt` and `abc.txt` In general, if a variable is annotated with `glob` type, nushell will expand glob pattern. Or else, we need to use `into | glob` to expand glob pattern # Tests + Formatting Done # After Submitting I think `str glob-escape` command will be no-longer required. We can remove it.
Description
This is a follow up to #11621 (comment)
Also Fixes: #11838
About the code change
It applys the same logic when we pass variables to external commands:
nushell/crates/nu-command/src/system/run_external.rs
Lines 162 to 170 in 0487e9f
That is: if user input dynamic things(like variables, sub-expression, or string interpolation), it returns a quoted
NuPath, then user input won't be globbedUser-Facing Changes
Given two input files:
a*c.txt,abc.txtlet f = "a*c.txt"; rm $fwill remove one file:a*c.txt.*let f = "a*c.txt"; rm --glob $fwill removea*c.txtandabc.txtlet f: glob = "a*c.txt"; rm $fwill removea*c.txtandabc.txtRules about globbing with variable
Given two files:
a*c.txt,abc.txta*c.txta*c.txtandabc.txta*c.txtandabc.txta*c.txtandabc.txta*c.txta*c.txta*c.txtandabc.txtIn general, if a variable is annotated with
globtype, nushell will expand glob pattern. Or else, we need to useinto | globto expand glob patternTests + Formatting
Done
After Submitting
I think
str glob-escapecommand will be no-longer required. We can remove it.