PSReadLine icon indicating copy to clipboard operation
PSReadLine copied to clipboard

Have a function to allow interactive search of history showing multiple matches

Open SteveL-MSFT opened this issue 5 years ago • 5 comments

Currently, you can use history search function, but it only shows one line that currently matches. Would be interesting to have a menu complete type experience where it shows you a bunch of matches you can scroll through

SteveL-MSFT avatar Jun 02 '20 16:06 SteveL-MSFT

PSFzf provides a good experience like this.

lzybkr avatar Jun 02 '20 22:06 lzybkr

Currently, you can use history search function, but it only shows one line that currently matches. Would be interesting to have a menu complete type experience where it shows you a bunch of matches you can scroll through

It would be a nice feature (similar to the old F7 command in cmd.exe), though I've always got pretty good mileage out of: #searchTerm<tab> to cycle through commands in history that match the term. It doesn't bring them all up at once like menu complete but still pretty useful. If I really want to see a bunch of similar commands, I can always use Get-History piped to a where clause. FWIW...

MatthewSteeves avatar Oct 08 '20 17:10 MatthewSteeves

@SteveL-MSFT, what if the search results where displayed similar to ListView in Predictive IntelliSense and could be selected? Another thought - with the historical predictor already producing similar results, is enhancing the search function still needed?

theJasonHelmick avatar Apr 06 '21 17:04 theJasonHelmick

@MatthewSteeves Get-History doesn't look at the history file, so isn't an option in this case. Same thing with #searchTerm. Those both only hit the built in PowerShell history and don't reference the history file at all.

You could do something similar to Get-History by using the following. [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems() | Where-Object { $_.CommandLine -match '<searchTerm>' } But that won't get the original request, it just lets you search the history programmatically and see multiple results. The results don't let you pick from them, just see them. But I still find it useful if I know there will be a lot of matches.

FireInWinter avatar Oct 19 '21 14:10 FireInWinter

@FireInWinter Thanks for pointing out - wasn't aware of the difference.

MatthewSteeves avatar Oct 19 '21 16:10 MatthewSteeves