PowerShell / PSReadLine

A bash inspired readline implementation for PowerShell
BSD 2-Clause "Simplified" License
3.75k stars 296 forks source link

PSReadLine history search with wildcards #3681

Open fullenw1 opened 1 year ago

fullenw1 commented 1 year ago

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

jhoneill commented 1 year ago

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.

fullenw1 commented 1 year ago

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
GitHub - Ink230/DirectoryPredictor: PowerShell Module which displays related files, actively from the current directory, in your PSReadLine autocompletion list.
PowerShell Module which displays related files, actively from the current directory, in your PSReadLine autocompletion list. - GitHub - Ink230/DirectoryPredictor: PowerShell Module which displays r...
kilasuit commented 1 year ago

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

kilasuit commented 1 year ago

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

daxian-dbw commented 1 year ago

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

fullenw1 commented 1 year ago

@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.