Skip to content

Commit 219ffa1

Browse files
authored
Allow MaximumHistoryCount to be set from user's profile (#1869)
1 parent e08072d commit 219ffa1

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

PSReadLine/Cmdlets.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ public PSConsoleReadLineOptions(string hostName)
159159
ExtraPromptLineCount = DefaultExtraPromptLineCount;
160160
AddToHistoryHandler = DefaultAddToHistoryHandler;
161161
HistoryNoDuplicates = DefaultHistoryNoDuplicates;
162-
MaximumHistoryCount = DefaultMaximumHistoryCount;
163162
MaximumKillRingCount = DefaultMaximumKillRingCount;
164163
HistorySearchCursorMovesToEnd = DefaultHistorySearchCursorMovesToEnd;
165164
ShowToolTips = DefaultShowToolTips;
@@ -172,6 +171,7 @@ public PSConsoleReadLineOptions(string hostName)
172171
HistorySaveStyle = DefaultHistorySaveStyle;
173172
AnsiEscapeTimeout = DefaultAnsiEscapeTimeout;
174173
PredictionSource = DefaultPredictionSource;
174+
MaximumHistoryCount = 0;
175175

176176
var historyFileName = hostName + "_history.txt";
177177
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

PSReadLine/ReadLine.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,10 +757,13 @@ private void DelayedOneTimeInitialize()
757757
// specifies a custom history save file, we don't want to try reading
758758
// from the default one.
759759

760-
var historyCountVar = _engineIntrinsics?.SessionState.PSVariable.Get("MaximumHistoryCount");
761-
if (historyCountVar?.Value is int historyCountValue)
760+
if (_options.MaximumHistoryCount == 0)
762761
{
763-
_options.MaximumHistoryCount = historyCountValue;
762+
// Initialize 'MaximumHistoryCount' if it's not defined in user's profile.
763+
var historyCountVar = _engineIntrinsics?.SessionState.PSVariable.Get("MaximumHistoryCount");
764+
_options.MaximumHistoryCount = (historyCountVar?.Value is int historyCountValue)
765+
? historyCountValue
766+
: PSConsoleReadLineOptions.DefaultMaximumHistoryCount;
764767
}
765768

766769
if (_options.PromptText == null &&

0 commit comments

Comments
 (0)