PowerShell / PSReadLine

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

Make history prediction location aware #3472

Open SteveL-MSFT opened 1 year ago

SteveL-MSFT commented 1 year ago

Prerequisites

Description of the new feature/enhancement

Include the current location (working directory) as part of history so that predictions based on history would show commands used from that location previously. If nothing is found, then fallback to current strategy.

Example:

> cd ~/repos/powershell
~/repos/powershell> git re

# prediciton would be something like: git reset --hard upstream/master

> cd ~/repos/somethingelse
~/repos/somethingelse> git re

# prediction would be something like: git reset --hard upstream/main
# in this example, you use `main` instead of `master` branch

Proposed technical implementation details (optional)

No response

daxian-dbw commented 1 year ago

The location awareness for history should not be applied globally, but should only be applied to the selected commands.

For commands like git, it usually has strong association with the folder where it runs in, so history about it should be location aware.

However, there are many other commands that have less or none association with the location where it runs in, such as azure commands, postman, dumpbin, and a lot more. For those command, history entries about them should always be presented to users, regardless of which folder they were executed in previously.

So, it's probably safer not enable folder awareness in history prediction by default, but allow user's configuration on this -- a user can say I want history prediction to apply location awareness to git command only.

Supporting this will require moving to database for storing history entries. A lot of thoughts need to be put into the user experience.

iksi4prs commented 1 year ago

@SteveL-MSFT @daxian-dbw Regarding my Q in discussions: #3634 is it all covered in this item and in #3380 ? 10x.

SteveL-MSFT commented 1 year ago

@iksi4prs I believe the feature in this issue would resolve those two issues

iksi4prs commented 1 year ago

@SteveL-MSFT , Thank you for your answer. @daxian-dbw referred me to some example implementation of CommandPredictor. I think what I want to achieve, can be done via my own custom CommandPredictor, but I see that PSSubsystemPluginModel (which from what I understand is required for CommandPredictor) is experimental. (https://learn.microsoft.com/en-us/powershell/scripting/learn/experimental-features?view=powershell-7.3) Do you have any timeline/due date, to decide if this moves from status of "experimental" to removed/mainstream ? I don't want to put some effort, and see it is removed in 7.5 (like PSNativePSPathResolution was removed in 7.3) Or maybe I can vote for it with some examples ?