-
Notifications
You must be signed in to change notification settings - Fork 0
/
History-F7.ps1
43 lines (40 loc) · 1.67 KB
/
History-F7.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function ocgv_history {
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
$selection = $history | 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.Lenght)
}
}
}
$parameters = @{
Key = 'F7'
BriefDescription = 'ShowMatchingHistoryOcgv'
LongDescription = 'Show Matching History using Out-ConsoleGridView'
ScriptBlock = {
param($key, $arg) # The arguments are Ignored in the example
$history = Get-History | Sort-Object -Descending -Property Id -Unique | Select-Object CommandLine -ExpandProperty CommandLine
$history | 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 the example
$history = [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems().CommandLine
# reverse the items to most recent is on top
[array]::Reverse($history)
$history | Select-Object -Unique | ocgv_history
}
}
Set-PSReadLineKeyHandler @parameters