Skip to content

Commit 3c6ea48

Browse files
committed
Merge pull request #235 from andrewducker/master
Adding in an F7 handler to bring up command history in a grid.
2 parents 4cc069e + 096b105 commit 3c6ea48

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

PSReadLine/SamplePSReadlineProfile.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ Set-PSReadLineOption -HistorySearchCursorMovesToEnd
1818
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
1919
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
2020

21+
# Being able to search the entirety of your history in a popup makes it
22+
# really easy to find a command you previously used.
23+
# Either press F7 to bring up your entire history, or type part of the
24+
# command line and then press F7 to bring up just the commands that match.
25+
Set-PSReadlineKeyHandler -Key F7 `
26+
-BriefDescription History `
27+
-LongDescription 'Show history' `
28+
-ScriptBlock {
29+
$history = [System.Collections.ArrayList]([System.IO.File]::ReadAllLines((Get-PSReadlineOption).HistorySavePath))
30+
$history.Reverse()
31+
32+
$line = $null
33+
$cursor = $null
34+
[PSConsoleUtilities.PSConsoleReadline]::GetBufferState([ref]$line, [ref]$cursor)
35+
if ($line) {
36+
$history = $history -match [regex]::Escape($line)
37+
}
38+
39+
$command = $history | Get-Unique | Out-GridView -Title History -PassThru
40+
if ($command) {
41+
[PSConsoleUtilities.PSConsoleReadLine]::RevertLine()
42+
[PSConsoleUtilities.PSConsoleReadLine]::Insert($command)
43+
}
44+
}
45+
2146
# This is an example of a macro that you might use to execute a command.
2247
# This will add the command to history.
2348
Set-PSReadlineKeyHandler -Key Ctrl+B `

0 commit comments

Comments
 (0)