PowerShell / PSReadLine

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

Remove cmdlet/cmd that error from history to reduce confusion #3517

Open StevenBucher98 opened 1 year ago

StevenBucher98 commented 1 year ago

Prerequisites

Description of the new feature/enhancement

When there is a cmdlet or command that errors, we should utilize the experimental feedback provider (or other method) to recognize that it was in fact an error and then remove the last line from the history PSReadLine uses for history predictions. This way historical predictions can only suggest commands that were successful. This should not remove it from the session history, only the PSReadLine history

Some questions:

Proposed technical implementation details (optional)

No response

daxian-dbw commented 1 year ago

Are erroring commands distracting for the user to have in history predictions?

Not necessarily in my opinion. When the execution of a command line failed, it doesn't necessarily mean the command line itself has problem -- it could be some context state is different in this session, such as Az account not logged in yet, or Az context is with a different subscription, or even a variable used in this command line was not populated beforehand, and etc.

Command line execution failure from those scenarios are not distracting and should be put in history files, otherwise it will be a surprise to the user.

In most cases, execution failure because of typo in command name is distracting in history prediction, but PSReadLine already provides a way for users to register a validation handler before returning the command-line to PowerShell engine for execution, also there is history saving handler, which users can customize whether they want to save a particular command line to history or not.