Reputation: 936
In bash there's a nice feature that when a string is partially completed (like a path) and we use tab for autocompletion, we get ALL the possible options echoed out at once to aid the next character we might want to type.
In PowerShell, it just cycles through one option at a time, so you are relatively blind where numerous possibilities are involved.
Is equivalent behaviour possible in PowerShell?
Upvotes: 0
Views: 201
Reputation: 437953
Use Set-PSReadLineKeyHandler
to redefine what happens when you press Tab as follows:
Set-PSReadLineKeyHandler Tab MenuComplete
Note that you'll have to add this command to your $PROFILE
file in order to make it take effect in future sessions too.
The behavior of the MenuComplete
function is as follows:
ShowParameterHelp
function, available in PowerShell (Core) 7.2+, which is bound to Alt+h by default.Additional PSReadLine
tips:
To see a list of available functions:
Consult the about_PSReadLine_Functions
help topic; if it isn't available locally (with Get-Help about_PSReadLine_Functions
), run Update-Help -Module PSReadLine
.
To list all functions grouped by functional category, using Get-PSReadLineKeyHandler
:
Get-PSReadLineKeyHandler -Bound -Unbound
To see a flat list sorted by function name instead:
Get-PSReadLineKeyHandler -Bound -Unbound |
Sort-Object Function |
Select-Object Function, Key, Description
To check what key chord(s) a given function is currently bound to:
# This example looks for function names that contain the word "menu"
# Use -eq with a full function name, if known.
Get-PSReadLineKeyHandler | Where-Object Function -like *Menu*
To discover what function is currently bound to a given key chord:
Use the WhatIsKey
function, which on Windows is bound to Alt+? by default; on Unix-like platforms, where the range of usable key chords is limited, there is no default binding, but you can define one as follows, using Alt+w
as an example:
Set-PSReadLineKeyHandler Alt+w WhatIsKey
Pressing the key chord that WhatIsKey
is bound to then prompts for pressing the key chord of interest, which, if it is bound, prints the bound function name and its description.
[1] The possible completions are not shown in alphabetical order; instead, the order appears to be based on the parameter definition order, combined with some additional logic: an exact match is listed first, alias names are listed after their original names, dynamic parameters are listed after static ones, and matching common parameter names come last.
Upvotes: 4