powershellpowershell-7.0psreadline

Powershell PSReadLine : Get Key's for a given Function?


In PSReadLine 2.2.2 for PowerShell 7.2.11, On Windows, you can also use the Alt+? key chord to show the function bound to the next key chord you enter.

Conversely, is there a key or PS command that will show keys for a given function?

For example, how can I accomplish:

- Show all keys that are bound for the BackwardDeleteChar function?

Key       Function           Description
---       --------           -----------
Backspace BackwardDeleteChar Delete the character before the cursor
Ctrl+h    BackwardDeleteChar Delete the character before the cursor

or
- Show all keys that are bound for the MenuComplete function>

Key           Function            Description
---           --------            -----------
Ctrl+@        MenuComplete        Complete the input if there ...
Ctrl+Spacebar MenuComplete        Complete the input if there ...

Solution

  • Use the Where-Object cmdlet to filter the output from Get-PSReadLineKeyHandler:

    PS ~> Get-PSReadLineKeyHandler |Where-Object Function -eq MenuComplete
    
    Completion functions
    ====================
    
    Key           Function            Description
    ---           --------            -----------
    Ctrl+@        MenuComplete        Complete the input if there ...
    Ctrl+Spacebar MenuComplete        Complete the input if there ...