Skip to content

Instantly share code, notes, and snippets.

@fbehrens
Created February 26, 2020 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbehrens/75375cbe337cbf0a34a150ecd95bbff3 to your computer and use it in GitHub Desktop.
Save fbehrens/75375cbe337cbf0a34a150ecd95bbff3 to your computer and use it in GitHub Desktop.
PSReadline Handler
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