Skip to content

Instantly share code, notes, and snippets.

@jccovey
Created December 27, 2025 17:33
Show Gist options
  • Select an option

  • Save jccovey/17a0e6ac064588c040c68164d0b2485f to your computer and use it in GitHub Desktop.

Select an option

Save jccovey/17a0e6ac064588c040c68164d0b2485f to your computer and use it in GitHub Desktop.
Powershell history browser
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