Created
September 7, 2022 09:54
-
-
Save bielawb/2d93a56aac1631e29e1636f0a98df5c5 to your computer and use it in GitHub Desktop.
Fix $__ in PS7 with PSReadLine/ replacing it with Get-History call.
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 Spacebar -ScriptBlock { | |
param ($key, $arg) | |
$line = $null | |
$cursor = $null | |
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState( | |
[ref]$line, [ref]$cursor | |
) | |
if ($cursor -lt 3) { | |
return | |
} | |
$replacement = '(Get-History)[-1].Output' | |
if ($line.Substring(($cursor - 3),3) -eq '$__') { | |
[Microsoft.PowerShell.PSConsoleReadLine]::Replace( | |
($cursor - 3), | |
3, | |
$replacement | |
) | |
[Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition(($cursor - 3 + $replacement.Length)) | |
} else { | |
[Microsoft.PowerShell.PSConsoleReadLine]::Insert(' ') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment