powershell 按F7展开搜索历史记录
【powershell 按F7展开搜索历史记录】Install-Module Microsoft.PowerShell.ConsoleGuiTools
code $profile
添加一下代码
# 按f7显示历史记录
function ocgv_history {
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
$selection = $input | Out-ConsoleGridView -Title "Select CommandLine from History" -OutputMode Single -Filter $line
if ($selection) {
[Microsoft.PowerShell.PSConsoleReadLine]::DeleteLine()
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($selection)
if ($selection.StartsWith($line)) {
[Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition($cursor)
}
else {
[Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition($selection.Length)
}
}
}$parameters = @{
Key = 'F7'
BriefDescription = 'ShowMatchingHistoryOcgv'
LongDescription = 'Show Matching History using Out-ConsoleGridView'
ScriptBlock = {
param($key, $arg)# The arguments are ignored in this example
Get-History | Sort-Object -Descending -Property Id -Unique | Select-Object CommandLine -ExpandProperty CommandLine |ocgv_history
}
}
Set-PSReadLineKeyHandler @parameters$parameters = @{
Key = 'Shift-F7'
BriefDescription = 'ShowMatchingGlobalHistoryOcgv'
LongDescription = 'Show Matching History for all PowerShell instances using Out-ConsoleGridView'
ScriptBlock = {
param($key, $arg)# The arguments are ignored in this example
$hist = [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems().CommandLine
# reverse the items so most recent is on top
[array]::Reverse($hist)
$hist | Select-Object -Unique -First 1000 | ocgv_history
}
}
Set-PSReadLineKeyHandler @parameters
推荐阅读
- 2021-02-17|2021-02-17 小儿按摩膻中穴-舒缓咳嗽
- 牛人进化+|牛人进化+ 按自己的意愿过一生
- 「按键精灵安卓版」关于全分辨率脚本的一些理解(非游戏app)
- ?2019-03-10
- 特别的假期
- 《按比分配的实际问题》教学反思
- Xcode|Xcode 11.2 开启推送按钮
- PHP|PHP 扩展开发检测清单(扩展开发必读)
- 生命是活的,让它自然而来展开
- 不想按部就班,那你又能干什么呢