PSReadLine
PSReadLine copied to clipboard
Set-PSReadlineOption -MaximumHistoryCount in PowerShell profile does not set correctly
Environment
PS version: 7.0.0-rc.2
PSReadline version: 2.0.0-rc2'; ProjectUri = 'https://github.com/PowerShell/PSReadLine
os: 10.0.18362.1 (WinBuild.160101.0800)
PS file version: 7.0.0.0
HostName: ConsoleHost
BufferWidth: 136
BufferHeight: 9000
Steps to reproduce
Set the MaximumHistoryCount in the PowerShell profile:
Import-Module PSReadLine
Set-PSReadlineOption -MaximumHistoryCount 100
Expected behavior
Get the MaximumHistoryCount in a started session:
Get-PSReadLineOption | select MaximumHistoryCount
MaximumHistoryCount
-------------------
100
Actual behavior
Get the MaximumHistoryCount in a started session:
Get-PSReadLineOption | select MaximumHistoryCount
MaximumHistoryCount
-------------------
4096
Updated the repro step to use 100 instead of [int]::MaxValue, as the latter will result in a out-of-memory exception if it works as expected, by trying to create an array of the size [int]::MaxValue.
This happens because DelayedOneTimeInitialize always set the MaximumHistoryCount to the value of $MaximumHistoryCount, even if the value has been set through Set-PSReadLineOption beforehand.
Reproduced in 2.3.4 and 7.3.8.
This is still an issue in 7.4.0. 3 years, so why hasn't this been fixed already?
# Set-Variable -Name MaximumHistoryCount -Value 8192
# (Get-PSReadLineOption).MaximumHistoryCount
4096
Is there a work around?