From 1d4b288a5db0abeebbe2d6c67c130eaee461a8b7 Mon Sep 17 00:00:00 2001 From: cpendery Date: Sun, 17 Sep 2023 02:22:07 -0400 Subject: [PATCH] fix: update powershell bindings to have better UI Signed-off-by: cpendery --- shell/key-bindings.ps1 | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/shell/key-bindings.ps1 b/shell/key-bindings.ps1 index 30af8f0..ffdd4e9 100644 --- a/shell/key-bindings.ps1 +++ b/shell/key-bindings.ps1 @@ -1,9 +1,40 @@ -Set-PSReadLineKeyHandler -Chord "Ctrl+a" -ScriptBlock { +Set-PSReadLineKeyHandler -Chord 'Ctrl+a' -ScriptBlock { + $command = $null + [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$null) + + $oldPrompt = $function:prompt + function prompt {" `n"} + [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt() + $prompt = $oldPrompt + [Microsoft.PowerShell.PSConsoleReadLine]::ClearKillRing() [Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine() [Microsoft.PowerShell.PSConsoleReadLine]::KillLine() - [Microsoft.PowerShell.PSConsoleReadLine]::Insert('.\clac.exe "') - [Microsoft.PowerShell.PSConsoleReadLine]::Yank() - [Microsoft.PowerShell.PSConsoleReadLine]::Insert('" ; .\clac.exe -o | iex') + + if ($command) { + Start-Process -NoNewWindow -Wait ".\clac" "$command" + } else { + Start-Process -NoNewWindow -Wait ".\clac" + } + + $pinfo = New-Object System.Diagnostics.ProcessStartInfo + $pinfo.FileName = ".\clac" + $pinfo.RedirectStandardError = $true + $pinfo.RedirectStandardOutput = $true + $pinfo.UseShellExecute = $false + $pinfo.Arguments = "-o" + $p = New-Object System.Diagnostics.Process + $p.StartInfo = $pinfo + $p.Start() | Out-Null + $p.WaitForExit() + $stdout = $p.StandardOutput.ReadToEnd() + [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() + + $cmd,$args = $stdout -split ' ',2 + if ($cmd.Trim() -and $args.Trim()) { + Start-Process -NoNewWindow -Wait "$cmd" "$args" + } elseif ($cmd.Trim()) { + Start-Process -NoNewWindow -Wait "$cmd" + } } \ No newline at end of file