Repository navigation
Description
See also:
- Extend Get-Help to support online documentation lookup for built-in .NET types #11338
- Online support for about_... help topics #13550
Summary of the new feature/enhancement
PowerShell has a wealth of operators, many of them with sophisticated functionality, even in the case of operators familiar from other languages (e.g., * offering not just numeric multiplication, but also string replications).
To take full advantage of them, consulting the documentation is necessary, yet this documentation is currently hard to discover.
Get-Help should support an easy way to offer focused lookup of the documentation for any given operator, via the operator symbols themselves - ideally by showing / navigation to just the relevant portion of the enclosing about_*Operators* page or similar.
Proposed technical implementation details (optional)
Here's how it could work:
# WISHFUL THINKING
# Lists the names of all about_*Operators* topics.
Get-Help -Category Operator
# Opens the help topic (section) for the -replace operator.
# Allow omitting the initial '-'; if you do specify it, quote the entire argument.
Get-Help -Category Operator -Name 'replace'
# For simplicity, if the (positional) -Name argument is unambiguously an operator symbol,
# do not require -Category Operator
# Ignore whitespace in all arguments, so that, e.g., '@( )` works in addition to '@()'
Get-Help '@()' # -Category Operator implied
Get-Help '-replace'
Get-Help '%'
Get-Help '>'
Get-Help '--%' # not technically an operator, but we should support it too
# Quotes aren't technically operators, but we should support them too:
# All of these could open the about_Quoting_Rules topic.
Get-Help '"' # or: '""'
Get-Help "'" # or: "''"
Get-Help "@'" # or: "@''@"
Get-Help '@"' # or: '@""@'
# Ambiguous symbols
Get-Help '[]' # either default to indexer over casts / type constraints, or list both to force disambiguation
Get-Help '[0]' # interpret as indexer; also: Get-Help '["foo"]'
Get-Help '[int]' # interpret as cast / type constraint; any non-numeric unquoted name should work
Get-Help '.' # default to member-access over dot-sourcing; print hint for how to look up dot-sourcing
Get-Help '. ' # dot-sourcing (trailing space disambiguates)
Get-Help '&' # default to call operator over background operator, print hint for how to look up the background operator
Get-Help ' &' # background operator (leading space disambiguates)
Get-Help '@' # default to splatting, but print hint for how to look up @() and @'...'@It would also be helpful to be able to output a concise table of operators, along the following lines:
# Not sure what the best syntax is here; maybe include it in about_Operators with links to
# the operator-specific descriptions.
# Note the 'LookupName' column which shows how to resolve ambiguities.
PS> Get-Help about_OperatorTableName FriendlyName Category LookupName
---- ------------ -------- ----------
--% stop-parsing symbol ArgumentPassing
@ splatting ArgumentPassing
- subtraction / sign inversion Arithmetic
* multiplication / string replication Arithmetic
...
+ addition / string concatenation Arithmetic
, array constructor Array
.. range (numbers/characters) Array
-- decrement Assignment
-= compound assignment Assignment
...
-band bitwise AND Bitwise
-bNot bitwise complement Bitwise
...
?: ternary conditional Conditional
?? null-coalescing Conditional
-contains collection contains RHS Containment
-in LHS contained in RHS Containment
-notContains collection doesn't contain RHS Containment
-notIn LHS not contained in collection Containment
-eq equality Equality
-ge greater-than-or-equal Equality
# ...
@() array-subexpression Evaluation
$() subexpression Evaluation
. (dot-)source Execution '. '
& background Execution ' &'
& call (execute) Execution
-and logical AND Logical
...
Note:
-
For offline use in the console, the current help topics aren't structured enough to show the relevant topic excerpts focused just on the specified operator.
-
However, for online, browser-based lookups this already works via HTML anchors; e.g.,
-replaceis described specifically at https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Comparison_Operators?view=powershell-7#replacement-operator -
Some operators don't have individual sections even online, such as the arithmetic operators, but the enclosing topic is then usually short enough to find the information of interest easily.
-
-
For an implementation of this functionality as PowerShell function
Show-OperatorHelp(focused on operators only and only with online lookup), see this Stack Overflow answer.
Activity
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.