如何让Powershell TabExpansion打印所有可能的完成?

时间:2022-09-26 21:27:04

The default TabExpansion in Powershell cycles through the possible completions for the fragment on the command prompt. Internally in the PowerShell host, there's a circular buffer, and the first TAB fills the buffer and puts the first potential completion on the prompt. Subsequent TABs cycle through the list of possible completions.

Powershell中的默认TabExpansion在命令提示符下循环完成片段的可能完成。在PowerShell主机内部,有一个循环缓冲区,第一个TAB填充缓冲区并在提示符下放置第一个可能的完成。随后的TAB将循环显示可能的完成列表。

How can I modify TabExpansion to just display the set of possible completions when I hit ?

如何修改TabExpansion以便在我点击时显示可能的完成集?

Also, can I invoke the TabExpansion function explicitly from the command prompt, and if so, how?

另外,我可以从命令提示符中显式调用TabExpansion函数,如果是,如何调用?

(If you don't know what I mean by "modify TabExpansion", see this link.)

(如果您不知道“修改TabExpansion”的含义,请参阅此链接。)

4 个解决方案

#1


Check out PowerTab. It's pretty cool.

查看PowerTab。它太酷了。

UPDATE

Download PowerTab at CodePlex.

在CodePlex上下载PowerTab。

#2


see here. http://www.leeholmes.com/blog/AddingDoubleTapTabCompletionToPowerShell.aspx

看这里。 http://www.leeholmes.com/blog/AddingDoubleTapTabCompletionToPowerShell.aspx

#3


You can modify it directly at the prompt --or in your profile script-- it's just a function, so you could type this at a prompt to alter it to print all answers:

您可以在提示符处直接修改它 - 或者在您的配置文件脚本中 - 它只是一个函数,因此您可以在提示符下键入它以更改它以打印所有答案:

Copy Function:\TabExpansion Function:\OriginalTabExpansion
function TabExpansion([string] $line, [string] $lastword) { 
   OriginalTabExpansion $line $lastword | Out-Host
   $line
}

Or you can go a little further and format it wide:

或者你可以更进一步,格式化:

Copy Function:\TabExpansion Function:\OriginalTabExpansion
function TabExpansion([string] $line, [string] $lastword) { 
   Write-Host # an emtpy newline to avoid outputting on the prompt line
   # A hack, because Format-Wide doesn't work on strings 
   $obj = new-object psobject | add-member noteproperty value "" -Passthru
   OriginalTabExpansion $line $lastword | ForEach { $obj.value = $_; $obj } | 
      Format-Wide -auto value | Out-Host
   ## Maybe even re-output your prompt function... depending on how it's written
   Write-Host $(prompt) -NoNewLine
   return $line # keep the command as it was
}

PS: Vote for the bug on Format-Wide

PS:投票支持Format-Wide上的错误

#4


This one-liner seems to work around the problem with format-wide and an array of strings:

这个单线程似乎解决了格式范围和字符串数组的问题:

$ComputerList | Select-Object -Property @{Expression={[Object[]] $_};Name="Name"} | Format-Wide -Property Name -Column 5

$ ComputerList | Select-Object -Property @ {Expression = {[Object []] $ _}; Name =“Name”} |格式宽属性名称 - 列5

The array of strings in this case is $ComputerList defined like this:

在这种情况下,字符串数组是$ ComputerList定义如下:

[array] $ComputerList = @("WINSRV2003-32B","WINSRV2003-64B")

[array] $ ComputerList = @(“WINSRV2003-32B”,“WINSRV2003-64B”)

#1


Check out PowerTab. It's pretty cool.

查看PowerTab。它太酷了。

UPDATE

Download PowerTab at CodePlex.

在CodePlex上下载PowerTab。

#2


see here. http://www.leeholmes.com/blog/AddingDoubleTapTabCompletionToPowerShell.aspx

看这里。 http://www.leeholmes.com/blog/AddingDoubleTapTabCompletionToPowerShell.aspx

#3


You can modify it directly at the prompt --or in your profile script-- it's just a function, so you could type this at a prompt to alter it to print all answers:

您可以在提示符处直接修改它 - 或者在您的配置文件脚本中 - 它只是一个函数,因此您可以在提示符下键入它以更改它以打印所有答案:

Copy Function:\TabExpansion Function:\OriginalTabExpansion
function TabExpansion([string] $line, [string] $lastword) { 
   OriginalTabExpansion $line $lastword | Out-Host
   $line
}

Or you can go a little further and format it wide:

或者你可以更进一步,格式化:

Copy Function:\TabExpansion Function:\OriginalTabExpansion
function TabExpansion([string] $line, [string] $lastword) { 
   Write-Host # an emtpy newline to avoid outputting on the prompt line
   # A hack, because Format-Wide doesn't work on strings 
   $obj = new-object psobject | add-member noteproperty value "" -Passthru
   OriginalTabExpansion $line $lastword | ForEach { $obj.value = $_; $obj } | 
      Format-Wide -auto value | Out-Host
   ## Maybe even re-output your prompt function... depending on how it's written
   Write-Host $(prompt) -NoNewLine
   return $line # keep the command as it was
}

PS: Vote for the bug on Format-Wide

PS:投票支持Format-Wide上的错误

#4


This one-liner seems to work around the problem with format-wide and an array of strings:

这个单线程似乎解决了格式范围和字符串数组的问题:

$ComputerList | Select-Object -Property @{Expression={[Object[]] $_};Name="Name"} | Format-Wide -Property Name -Column 5

$ ComputerList | Select-Object -Property @ {Expression = {[Object []] $ _}; Name =“Name”} |格式宽属性名称 - 列5

The array of strings in this case is $ComputerList defined like this:

在这种情况下,字符串数组是$ ComputerList定义如下:

[array] $ComputerList = @("WINSRV2003-32B","WINSRV2003-64B")

[array] $ ComputerList = @(“WINSRV2003-32B”,“WINSRV2003-64B”)