Skip to content

Commit 8773a18

Browse files
committed
Honor $MaximumHistoryCount
This history count was being ignored, and the default in PSReadline was 1024 instead of 4096 that PowerShell defaults to. The fix is to up the default, and safely set MaximumHistoryCount in PSReadline based on the variable when initializing the first time PSReadlne is called. Fixes #135
1 parent aa4f616 commit 8773a18

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

PSReadLine/Cmdlets.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class PSConsoleReadlineOptions
6969
/// <summary>
7070
/// The maximum number of commands to store in the history.
7171
/// </summary>
72-
public const int DefaultMaximumHistoryCount = 1024;
72+
public const int DefaultMaximumHistoryCount = 4096;
7373

7474
/// <summary>
7575
/// The maximum number of items to store in the kill ring.

PSReadLine/PSReadLine.psm1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ function PSConsoleHostReadline
2222
$script:firstTime = $false
2323

2424
$options = [PSConsoleUtilities.PSConsoleReadLine]::GetOptions()
25+
26+
# Honor $MaximumHistoryCount, but get it safely in case it was removed in the profile.
27+
$MaximumHistoryCount = Get-Variable -ea Ignore -ValueOnly MaximumHistoryCount
28+
if ($MaximumHistoryCount -gt 0)
29+
{
30+
$options.MaximumHistoryCount = $MaximumHistoryCount
31+
[PSConsoleUtilities.PSConsoleReadLine]::SetOptions($options)
32+
}
33+
2534
if ($options.HistorySaveStyle -eq [PSConsoleUtilities.HistorySaveStyle]::SaveNothing)
2635
{
2736
# PSReadline isn't saving history, but we might still have history to reuse

0 commit comments

Comments
 (0)