Created
January 3, 2025 17:57
-
-
Save CN-CODEGOD/a231503b9e07e78b390b6b8bd361fa8d to your computer and use it in GitHub Desktop.
Powershell adding key function with psreadline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $parameters = @{ | |
| # setting key for psreadline | |
| Chord = if ($args.Count -eq 0 -or $null -eq $args[0]["Key"]) { "F7" } else { $args[0]["Key"] } | |
| BriefDescription = 'Show Matching Command History' | |
| Description = 'Show Matching Command History using Out-ConsoleGridView' | |
| #setting scriptblock for psreadline | |
| ScriptBlock = { | |
| $params = @{ Global = $false } | |
| if ($F7Diagnostic) { $params["Diagnostic"] = $true } | |
| if ($F7UseNetDriver) { $params["UseNetDriver"] = $true } | |
| f7_history @params | |
| } | |
| } | |
| #pass parameter to set-psreadlineKeyhandler | |
| Set-PSReadLineKeyHandler @parameters | |
| # When Shift-F7 is pressed, show the global command line history in OCGV | |
| $parameters = @{ | |
| Chord = if ($args.Count -eq 0 -or $null -eq $args[0]["AllKey"]) { "Shift-F7" } else { $args[0]["AllKey"] } | |
| BriefDescription = 'Show Matching Command History for All' | |
| Description = 'Show Matching Command History for all PowerShell instances using Out-ConsoleGridView' | |
| ScriptBlock = { | |
| $params = @{ Global = $true } | |
| if ($F7Diagnostic) { $params["Diagnostic"] = $true } | |
| if ($F7UseNetDriver) { $params["UseNetDriver"] = $true } | |
| f7_history @params | |
| } | |
| } | |
| Set-PSReadLineKeyHandler @parameters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment