Skip to content

Can't declare Ctrl+Question key binding #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rkeithhill opened this issue Sep 12, 2013 · 8 comments
Closed

Can't declare Ctrl+Question key binding #20

rkeithhill opened this issue Sep 12, 2013 · 8 comments
Labels
Issue-Enhancement It's a feature request.

Comments

@rkeithhill
Copy link
Contributor

If I attempt this I get the following error:

Set-PSReadlineKeyHandler : Cannot process argument transformation on parameter 'Key'. Unrecognized key 'question'.
Please use a character literal or a well-known key name from the System.ConsoleKey enumeration.
At C:\Users\Keith\Documents\WindowsPowerShell\profile.ps1:9 char:35

  • Set-PSReadlineKeyHandler -Key Ctrl+Question -BriefDescription GetKeyHandlers ...
    
  •                               ~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Set-PSReadlineKeyHandler], ParameterBindingArgumentTransformationExcep
      tion
    • FullyQualifiedErrorId : ParameterArgumentTransformationError,PSConsoleUtilities.SetKeyHandlerCommand

This is my handler decl:

Set-PSReadlineKeyHandler -Key Ctrl+Question -BriefDescription GetKeyHandlers -Handler { 
    [PSConsoleUtilities.PSConsoleReadLine]::GetKeyHandlers()
}
@cbadke
Copy link
Contributor

cbadke commented Oct 23, 2013

You can but you want Ctrl-? or more likely Ctrl-/

Set-PSReadlineKeyHandler -Key Ctrl+/ -ScriptBlock {
    [PSConsoleUtilities.PSConsoleReadline]::PossibleCompletions()
}

@rkeithhill
Copy link
Contributor Author

Yes, Ctrl+/ makes more sense (don't want to have to press Shift). But for help, what I was thinking is it would be the output of this command:

[PSConsoleUtilities.PSConsoleReadLine]::GetKeyHandlers()

Plus some general text info on how to use PSReadLine. Like if you're using less on a file and you press 'h' you get help on how to use less.

@cbadke
Copy link
Contributor

cbadke commented Oct 23, 2013

So would the remainder of your request be a duplicate of #24?

@rkeithhill
Copy link
Contributor Author

Well except that the keybinding Ctrl+/ doesn't work with the latest drop.

@cbadke
Copy link
Contributor

cbadke commented Oct 24, 2013

Seems to work for me. The code you posted in the original post doesn't work because the -Handler option does not exist. Does this not work for you?

Set-PSReadlineKeyHandler -Key Ctrl+/ -ScriptBlock {
    [PSConsoleUtilities.PSConsoleReadline]::PossibleCompletions()
}

Note that with this binding Ctrl+/ won't do anything unless you have enter something that can potentially be completed.

@rkeithhill
Copy link
Contributor Author

OK apparently the keybinding works but just not for GetKeyHandlers():

Set-PSReadlineKeyHandler -Key Ctrl+/ -ScriptBlock {
    [PSConsoleUtilities.PSConsoleReadline]::GetKeyHandlers()
}

Weird.

@lzybkr
Copy link
Contributor

lzybkr commented Oct 24, 2013

Not weird, it's by design. GetKeyHandlers doesn't have any side effects, so if it was bound to a key, it wouldn't be useful.

I do plan on adding what I think you want.

@lzybkr
Copy link
Contributor

lzybkr commented Dec 14, 2013

This is now addressed.

Get-PSReadlineKeyHandler should now look better and match what you would use with Set-PSReadlineKeyHandler.
New functions:

  • WhatIsKey (bound to Ctrl+?) will read the next key and tell you what it is bound to
  • ShowKeyBindings (bound to Ctrl+Alt+?) will output all of the bound keys like Get-PSReadlineKeyHandler, but it preserves the current line.

The actual commits:

2553fa3
653b492
1e2dee3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement It's a feature request.
Projects
None yet
Development

No branches or pull requests

3 participants