Skip to content

Commit

Permalink
Allow MaximumHistoryCount to be set from user's profile (#1869)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxian-dbw authored Oct 9, 2020
1 parent e08072d commit 219ffa1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion PSReadLine/Cmdlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ public PSConsoleReadLineOptions(string hostName)
ExtraPromptLineCount = DefaultExtraPromptLineCount;
AddToHistoryHandler = DefaultAddToHistoryHandler;
HistoryNoDuplicates = DefaultHistoryNoDuplicates;
MaximumHistoryCount = DefaultMaximumHistoryCount;
MaximumKillRingCount = DefaultMaximumKillRingCount;
HistorySearchCursorMovesToEnd = DefaultHistorySearchCursorMovesToEnd;
ShowToolTips = DefaultShowToolTips;
Expand All @@ -172,6 +171,7 @@ public PSConsoleReadLineOptions(string hostName)
HistorySaveStyle = DefaultHistorySaveStyle;
AnsiEscapeTimeout = DefaultAnsiEscapeTimeout;
PredictionSource = DefaultPredictionSource;
MaximumHistoryCount = 0;

var historyFileName = hostName + "_history.txt";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Expand Down
9 changes: 6 additions & 3 deletions PSReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,13 @@ private void DelayedOneTimeInitialize()
// specifies a custom history save file, we don't want to try reading
// from the default one.

var historyCountVar = _engineIntrinsics?.SessionState.PSVariable.Get("MaximumHistoryCount");
if (historyCountVar?.Value is int historyCountValue)
if (_options.MaximumHistoryCount == 0)
{
_options.MaximumHistoryCount = historyCountValue;
// Initialize 'MaximumHistoryCount' if it's not defined in user's profile.
var historyCountVar = _engineIntrinsics?.SessionState.PSVariable.Get("MaximumHistoryCount");
_options.MaximumHistoryCount = (historyCountVar?.Value is int historyCountValue)
? historyCountValue
: PSConsoleReadLineOptions.DefaultMaximumHistoryCount;
}

if (_options.PromptText == null &&
Expand Down

0 comments on commit 219ffa1

Please sign in to comment.