Created
December 27, 2025 17:33
-
-
Save jccovey/17a0e6ac064588c040c68164d0b2485f to your computer and use it in GitHub Desktop.
Powershell history browser
This file contains hidden or 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
| function hist { | |
| param([string]$find) | |
| if ([string]::IsNullOrWhiteSpace($find)) { | |
| Write-Host "Usage: hist <search_term><tab>" | |
| return | |
| } | |
| Invoke-Expression $find; | |
| } | |
| # Tab completion for PowerShell 5.1 | |
| Register-ArgumentCompleter -CommandName hist -ParameterName find -ScriptBlock { | |
| param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) | |
| # Get unique commands from history | |
| $historyCommands = Get-Content (Get-PSReadlineOption).HistorySavePath | | |
| Where-Object { $_ -like "*$wordToComplete*" } | | |
| Get-Unique | | |
| Select-Object -First 50 | |
| # Return completion results | |
| $historyCommands | ForEach-Object { | |
| [System.Management.Automation.CompletionResult]::new( | |
| "'$_'", | |
| $_, | |
| 'ParameterValue', | |
| $_ | |
| ) | |
| } | |
| } | |
| Set-PSReadLineKeyHandler -Chord 'Ctrl+e' -ScriptBlock { | |
| # Clear line and prompt for search | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine(); | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert('hist'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment