0

I tried to use psreadline today. There is something i don't understand is the history command.

When I run

Set-PSReadLineOption -PredictionSource 

The history suggestions start showing up.

I close the terminal ps, open it again, no history suggestions there until i run the command again.

What do I miss?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Oggy
  • 45
  • 3
  • This is not a PowerShell issue or failure. You do not have an issue, what you have is a misunderstanding. So read up on the help files for PSREadline. PSRealine notwithstanding, running command is just for that session unless you set it to options permanently via your profile or automatic variables/preference variables. – postanote Jun 05 '21 at 03:20

1 Answers1

1

If this is the only command you are using...

Set-PSReadLineOption -PredictionSource

.. then that is not complete.

As per the Powershell docs here: MS Docs | PSReadLine

-PredictionSource
Specifies the source for PSReadLine to get predictive suggestions.

Valid values are:

None: disable the predictive suggestion feature
History: get predictive suggestions from history only

So you have to tell it what you want:

Set-PSReadLineOption -PredictionSource History

or

Set-PSReadLineOption -PredictionSource None

The latter is the default if you don't tell it. Just put the former in all your console profiles.

Get-PSReadLineOption
<#
EditMode                               : Windows
AddToHistoryHandler                    : System.Func`2[System.String,System.Object]
HistoryNoDuplicates                    : True
HistorySavePath                        : C:\Users\WDAGUtilityAccount\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
...
PredictionSource                       : None
...
#>

Be sure to read up on ...

Set-PSReadLineOption -HistorySaveStyle

... and its options as well.

postanote
  • 15,138
  • 2
  • 14
  • 25