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