Tab completion: only complete filenames with wildcard-pattern escaping when binding to [SupportsWildcards()] parameters #14149
Labels
Issue-Enhancement
the issue is more of a feature request than a bug
Summary of the new feature/enhancement
Note:
The problem surfaces whenever file / directory names containing
[
and]
are completed.E.g., a file literally named
foo[1].txt
typically tab-completes asfoo`[1`].txt
rather than to the actual name, using the escaping rules of a wildcard pattern.Currently, the escaping logic when filenames are tab-completed appears to be as follows:
Escape by default,
except when binding to a parameter literally named
-LiteralPath
(using that name as an alias is not recognized).Instead, I propose the following logic:
Do not escape by default,
except when the target parameter is decorated with the
[SupportsWildCards()]
attribute.Benefits and impact:
For command parameters that properly decorate their wildcard-based parameters with this attribute - notably
-Path
, - the behavior won't change (escaping will be applied); among the built-in cmdlets that seems to be true (which a quick look atGet-Item
,Get-ChildItem
,Get-Content
, andSelect-String
tells me)In all other cases, unescaped completion will take place.
This allows command authors to control how filenames are completed, by indicating explicitly when wildcard support is desired.
If they want literal completion, no extra effort is needed, which avoids the awkward current workaround of having to name a parameter
-LiteralPath
, which isn't always appropriate.The text was updated successfully, but these errors were encountered: