Created
February 26, 2020 21:15
-
-
Save fbehrens/75375cbe337cbf0a34a150ecd95bbff3 to your computer and use it in GitHub Desktop.
PSReadline Handler
This file contains 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
Set-PSReadLineKeyHandler -Chord F2 -BriefDescription HashFromCsv -LongDescription "converts a comma separated String int a Hashtable" -ScriptBlock { param($key, $arg) | |
$line = $null | |
$cursor = $null | |
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor) | |
$g = [Regex]::matches($line,"\S+") | ? { $_.index -le $cursor -and $_.index + $_.Length -ge $cursor } | |
if (!$g){ return } | |
$s = $g.value -replace ",",'="";' | |
$s = "@{$s=`"`"}" | |
$pos = $s.IndexOf('""') | |
[Microsoft.PowerShell.PSConsoleReadLine]::Replace($g.Index,$g.Length,$s) | |
[Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition($g.Index + $pos + 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment