PSReadLine icon indicating copy to clipboard operation
PSReadLine copied to clipboard

PSReadLine history search with wildcards

Open fullenw1 opened this issue 2 years ago • 6 comments

Summary of the new feature / enhancement

Often I remember some elements of former command lines. However when I used the forward/backward search capability, I have usually to go trough a lot of suggestions before finding the match. Being able to use wild cards would dramatically improve the research experience.

Exemple of current behavior:

I need to search for a line with:

Get-ADUser -Property Description, Manager -Identity accountX

Currently I have to go through:

Get-ADUser -Identity accountA
Get-ADUser -Property Description -Identity accountC
Get-ADUser -Property Manager -Identity accountD
Get-ADUser -Property Description, Manager -Identity accountN
Get-ADUser -Property Description, Manager -Identity accountO
Get-ADUser -Property Description, Manager -Identity accountX

Request:

I wish I could make my search with:

Get-ADUser*accountX

Proposed technical implementation details (optional)

A similar feature already exists, though currently limited to the file system.

https://github.com/Ink230/DirectoryPredictor

fullenw1 avatar May 10 '23 09:05 fullenw1

The difficulty with this is I want to search for commands where I have done things with *.tmp or whatever, so how does one differentiate between searching for a wildcard, and searching with a wildcard.

If you have predictive history on you can toggle between "Suggest closest" and "Show me options" with F2. So for that example if I know the command is in the history but isn't the most recent I'll start with get-adu and then press F2 and pick the right one. Not perfect, especially if muscle memory is hard coded to # whatever or [ctrl]+[r] whatever, but another tool if it suits.

jhoneill avatar May 10 '23 10:05 jhoneill

The difficulty with this is I want to search for commands where I have done things with *.tmp or whatever, so how does one differentiate between searching for a wildcard, and searching with a wildcard.

If you have predictive history on you can toggle between "Suggest closest" and "Show me options" with F2. So for that example if I know the command is in the history but isn't the most recent I'll start with get-adu and then press F2 and pick the right one. Not perfect, especially if muscle memory is hard coded to # whatever or [ctrl]+[r] whatever, but another tool if it suits.

Yes, being able to use wildcards with predictive history would be great too! 😃

There is already somebody developing something similar but currently only limited to the filesystem. https://github.com/Ink230/DirectoryPredictor Maybe you should have a look...

GitHub
PowerShell Module which displays related files, actively from the current directory, in your PSReadLine autocompletion list. - GitHub - Ink230/DirectoryPredictor: PowerShell Module which displays r...

fullenw1 avatar May 10 '23 19:05 fullenw1

I think this issue should be moved across to the PSReadline repo - @SteveL-MSFT / @daxian-dbw can you do this for me?

kilasuit avatar May 13 '23 13:05 kilasuit

Also this perhaps would be something that could be better achieved whenever this issue gets implemented

kilasuit avatar May 13 '23 13:05 kilasuit

@fullenw1 Just so I'm clear, are you asking for wildcard matching in history prediction, or the history searching, like when using Ctrl+r?

daxian-dbw avatar May 15 '23 17:05 daxian-dbw

@fullenw1 Just so I'm clear, are you asking for wildcard matching in history prediction, or the history searching, like when using Ctrl+r?

@daxian-dbw , originally it was for the history searching, like when using CTRL + R.

However, one can assume that if wildcards can be used with the history prediction too, then the history searching would become nearly useless, except for those who don't want/like to use the history prediction.

Currently, I still use both. But I noticed that with the improvement of the history prediction (thanks to the CompletionPredictor module), I use less the history searching.

fullenw1 avatar May 22 '23 21:05 fullenw1