Last active
June 9, 2022 07:35
-
-
Save atsushifx/a9ae10e2d0cbab8df899aa9b410aa2ce to your computer and use it in GitHub Desktop.
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
<# | |
.SYNOPSIS | |
select command from history and execute | |
.DESCRIPTION | |
select history wuth peco and set command line to execute this. | |
.EXAMPLE | |
Set-PSReadLineKeyHandler -chord Ctrl+p -scriptBlock { SelectandExecHistory } | |
using above that hit ctrl+p to use this. | |
#> | |
function global:SelectandExecHistory() | |
{ | |
$selectCmd = (tail -20 (Get-PSReadLineOption).HistorySavePath)|peco --select-1 --on-cancel error | |
if ($?) { | |
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt() | |
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($selectCmd) | |
# [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine() | |
# [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
} else { | |
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment