OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

PowerShell: How to do Autocompletion for proxy functions?

  • Thread starter Thread starter Dmitrij Drandarov
  • Start date Start date
D

Dmitrij Drandarov

Guest
I have a function like:

Code:
function helf {
    Get-Help -Full @args
}

This results in autocompletion for helf -<tab> no longer working:

Code:
> TabExpansion2 "helf -" | select -Expand CompletionMatches
[ NO RESULT ]

I've noticed however that oss, which is actually not an alias of Out-String, but a proxy function of Out-String -Stream, does have working autocomplete:

Code:
> gcm oss

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        oss


Code:
> TabExpansion2 "Out-String -Stream -" | select -Expand CompletionMatches

CompletionText       ListItemText           ResultType ToolTip
--------------       ------------           ---------- -------
-Width               Width               ParameterName [int] Width
-InputObject         InputObject         ParameterName [psobject] InputObject
-Verbose             Verbose             ParameterName [switch] Verbose
-Debug               Debug               ParameterName [switch] Debug
-ErrorAction         ErrorAction         ParameterName [ActionPreference] ErrorAction
-WarningAction       WarningAction       ParameterName [ActionPreference] WarningAction
-InformationAction   InformationAction   ParameterName [ActionPreference] InformationAction
-ProgressAction      ProgressAction      ParameterName [ActionPreference] ProgressAction
-ErrorVariable       ErrorVariable       ParameterName [string] ErrorVariable
-WarningVariable     WarningVariable     ParameterName [string] WarningVariable
-InformationVariable InformationVariable ParameterName [string] InformationVariable
-OutVariable         OutVariable         ParameterName [string] OutVariable
-OutBuffer           OutBuffer           ParameterName [int] OutBuffer
-PipelineVariable    PipelineVariable    ParameterName [string] PipelineVariable


Code:
> TabExpansion2 "oss -" | select -Expand CompletionMatches

CompletionText       ListItemText           ResultType ToolTip
--------------       ------------           ---------- -------
-Width               Width               ParameterName [int] Width
-InputObject         InputObject         ParameterName [psobject] InputObject
-Verbose             Verbose             ParameterName [switch] Verbose
-Debug               Debug               ParameterName [switch] Debug
-ErrorAction         ErrorAction         ParameterName [ActionPreference] ErrorAction
-WarningAction       WarningAction       ParameterName [ActionPreference] WarningAction
-InformationAction   InformationAction   ParameterName [ActionPreference] InformationAction
-ProgressAction      ProgressAction      ParameterName [ActionPreference] ProgressAction
-ErrorVariable       ErrorVariable       ParameterName [string] ErrorVariable
-WarningVariable     WarningVariable     ParameterName [string] WarningVariable
-InformationVariable InformationVariable ParameterName [string] InformationVariable
-OutVariable         OutVariable         ParameterName [string] OutVariable
-OutBuffer           OutBuffer           ParameterName [int] OutBuffer
-PipelineVariable    PipelineVariable    ParameterName [string] PipelineVariable


The question is: How would I accomplish this for my own proxy functions?
<p>I have a function like:</p>
<pre><code>function helf {
Get-Help -Full @args
}
</code></pre>
<p>This results in autocompletion for <code>helf -<tab></code> no longer working:</p>
<pre><code>> TabExpansion2 "helf -" | select -Expand CompletionMatches
[ NO RESULT ]
</code></pre>
<p>I've noticed however that <code>oss</code>, which is actually not an alias of <code>Out-String</code>, but a proxy function of <code>Out-String -Stream</code>, does have working autocomplete:</p>
<pre><code>> gcm oss

CommandType Name Version Source
----------- ---- ------- ------
Function oss
</code></pre>
<hr />
<pre><code>> TabExpansion2 "Out-String -Stream -" | select -Expand CompletionMatches

CompletionText ListItemText ResultType ToolTip
-------------- ------------ ---------- -------
-Width Width ParameterName [int] Width
-InputObject InputObject ParameterName [psobject] InputObject
-Verbose Verbose ParameterName [switch] Verbose
-Debug Debug ParameterName [switch] Debug
-ErrorAction ErrorAction ParameterName [ActionPreference] ErrorAction
-WarningAction WarningAction ParameterName [ActionPreference] WarningAction
-InformationAction InformationAction ParameterName [ActionPreference] InformationAction
-ProgressAction ProgressAction ParameterName [ActionPreference] ProgressAction
-ErrorVariable ErrorVariable ParameterName [string] ErrorVariable
-WarningVariable WarningVariable ParameterName [string] WarningVariable
-InformationVariable InformationVariable ParameterName [string] InformationVariable
-OutVariable OutVariable ParameterName [string] OutVariable
-OutBuffer OutBuffer ParameterName [int] OutBuffer
-PipelineVariable PipelineVariable ParameterName [string] PipelineVariable
</code></pre>
<hr />
<pre><code>> TabExpansion2 "oss -" | select -Expand CompletionMatches

CompletionText ListItemText ResultType ToolTip
-------------- ------------ ---------- -------
-Width Width ParameterName [int] Width
-InputObject InputObject ParameterName [psobject] InputObject
-Verbose Verbose ParameterName [switch] Verbose
-Debug Debug ParameterName [switch] Debug
-ErrorAction ErrorAction ParameterName [ActionPreference] ErrorAction
-WarningAction WarningAction ParameterName [ActionPreference] WarningAction
-InformationAction InformationAction ParameterName [ActionPreference] InformationAction
-ProgressAction ProgressAction ParameterName [ActionPreference] ProgressAction
-ErrorVariable ErrorVariable ParameterName [string] ErrorVariable
-WarningVariable WarningVariable ParameterName [string] WarningVariable
-InformationVariable InformationVariable ParameterName [string] InformationVariable
-OutVariable OutVariable ParameterName [string] OutVariable
-OutBuffer OutBuffer ParameterName [int] OutBuffer
-PipelineVariable PipelineVariable ParameterName [string] PipelineVariable
</code></pre>
<hr />
<p>The question is: How would I accomplish this for my own proxy functions?</p>
Continue reading...
 

Latest posts

Online statistics

Members online
0
Guests online
3
Total visitors
3
Ads by Eonads
Top