mirror of
https://github.com/PowerShell/PSReadLine
synced 2026-06-08 12:12:13 +00:00
Remove MinimumHistoryCommandLength
People seem to prefer all commands in history, so it seems better to have
fewer options.
The following can be used if the previous functionality is desired:
Set-PSReadlineOption -AddToHistoryHandler { $args[0].Length -gt 3 }
This commit is contained in:
@@ -83,14 +83,6 @@ function global:PSConsoleHostReadline
|
||||
}
|
||||
internal SwitchParameter? _historySearchCursorMovesToEnd;
|
||||
|
||||
[Parameter(ParameterSetName = "OptionsSet")]
|
||||
public int MinimumHistoryCommandLength
|
||||
{
|
||||
get { return _minimumHistoryCommandLength.GetValueOrDefault(); }
|
||||
set { _minimumHistoryCommandLength = value; }
|
||||
}
|
||||
internal int? _minimumHistoryCommandLength;
|
||||
|
||||
[Parameter(ParameterSetName = "OptionsSet")]
|
||||
public int MaximumHistoryCount
|
||||
{
|
||||
|
||||
+1
-28
@@ -175,13 +175,6 @@ namespace PSConsoleUtilities
|
||||
/// </summary>
|
||||
private Func<string, bool> _addToHistoryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Commands shorter than MinimumHistoryCommandLength will not be added
|
||||
/// to the history.
|
||||
/// </summary>
|
||||
public const int DefaultMinimumHistoryCommandLength = 4;
|
||||
private int _minimumHistoryCommandLength;
|
||||
|
||||
/// <summary>
|
||||
/// When true, duplicates will not be added to the history.
|
||||
/// </summary>
|
||||
@@ -335,11 +328,7 @@ namespace PSConsoleUtilities
|
||||
|
||||
private string MaybeAddToHistory(string result)
|
||||
{
|
||||
bool addToHistory = (result.Length >= _minimumHistoryCommandLength);
|
||||
if (addToHistory && _addToHistoryHandler != null)
|
||||
{
|
||||
addToHistory = _addToHistoryHandler(result);
|
||||
}
|
||||
bool addToHistory = (_addToHistoryHandler == null) || _addToHistoryHandler(result);
|
||||
if (addToHistory && _historyNoDuplicates)
|
||||
{
|
||||
// REVIEW: should history be case sensitive - it is now.
|
||||
@@ -458,7 +447,6 @@ namespace PSConsoleUtilities
|
||||
_continuationPromptForegroundColor = DefaultContinuationPromptForegroundColor;
|
||||
_continuationPromptBackgroundColor = DefaultContinuationPromptBackgroundColor;
|
||||
|
||||
_minimumHistoryCommandLength = DefaultMinimumHistoryCommandLength;
|
||||
_addToHistoryHandler = null;
|
||||
_historyNoDuplicates = DefaultHistoryNoDuplicates;
|
||||
_maximumHistoryCount = DefaultMaximumHistoryCount;
|
||||
@@ -1791,21 +1779,6 @@ namespace PSConsoleUtilities
|
||||
{
|
||||
_addToHistoryHandler = options.AddToHistoryHandler;
|
||||
}
|
||||
if (options._minimumHistoryCommandLength.HasValue)
|
||||
{
|
||||
_minimumHistoryCommandLength = options.MinimumHistoryCommandLength;
|
||||
var newHistory = new HistoryQueue<string>(_maximumHistoryCount);
|
||||
while (_history.Count > 0)
|
||||
{
|
||||
var item = _history.Dequeue();
|
||||
if (item.Length >= _minimumHistoryCommandLength)
|
||||
{
|
||||
newHistory.Enqueue(item);
|
||||
}
|
||||
}
|
||||
_history = newHistory;
|
||||
_currentHistoryIndex = _history.Count;
|
||||
}
|
||||
if (options._maximumHistoryCount.HasValue)
|
||||
{
|
||||
_maximumHistoryCount = options.MaximumHistoryCount;
|
||||
|
||||
@@ -453,7 +453,6 @@ namespace UnitTestPSReadLine
|
||||
{
|
||||
AddToHistoryHandler = null,
|
||||
HistoryNoDuplicates = PSConsoleReadLine.DefaultHistoryNoDuplicates,
|
||||
MinimumHistoryCommandLength = PSConsoleReadLine.DefaultMinimumHistoryCommandLength,
|
||||
MaximumHistoryCount = PSConsoleReadLine.DefaultMaximumHistoryCount,
|
||||
MaximumKillRingCount = PSConsoleReadLine.DefaultMaximumKillRingCount,
|
||||
ResetTokenColors = true,
|
||||
@@ -886,26 +885,6 @@ namespace UnitTestPSReadLine
|
||||
result = Test(keys5); Assert.AreEqual("aaaa", result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestHistoryMinimumCommandLength()
|
||||
{
|
||||
TestSetup(KeyMode.Cmd);
|
||||
PSConsoleReadLine.SetOptions(new SetPSReadlineOption {MinimumHistoryCommandLength = 6});
|
||||
|
||||
var keys = new [] {_.A, _.B, _.C, _.D, _.E, _.F, _.G, _.H, _.Enter};
|
||||
var result = Test(keys); Assert.AreEqual("abcdefgh", result);
|
||||
keys = new [] {_.A, _.B, _.C, _.D, _.E, _.F, _.Enter};
|
||||
result = Test(keys); Assert.AreEqual("abcdef", result);
|
||||
keys = new [] {_.A, _.B, _.C, _.D, _.E, _.Enter};
|
||||
result = Test(keys); Assert.AreEqual("abcde", result);
|
||||
keys = new [] {_.UpArrow, _.Enter};
|
||||
result = Test(keys); Assert.AreEqual("abcdef", result);
|
||||
|
||||
PSConsoleReadLine.SetOptions(new SetPSReadlineOption {MinimumHistoryCommandLength = 7});
|
||||
keys = new [] {_.UpArrow, _.Enter};
|
||||
result = Test(keys); Assert.AreEqual("abcdefgh", result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestHistoryCount()
|
||||
{
|
||||
@@ -1419,7 +1398,6 @@ namespace UnitTestPSReadLine
|
||||
+ options.HistorySearchCursorMovesToEnd.GetHashCode()
|
||||
+ options.MaximumHistoryCount.GetHashCode()
|
||||
+ options.MaximumKillRingCount.GetHashCode()
|
||||
+ options.MinimumHistoryCommandLength.GetHashCode()
|
||||
+ options.DingDuration.GetHashCode()
|
||||
+ options.DingTone.GetHashCode()
|
||||
+ options.BellStyle.GetHashCode()
|
||||
|
||||
Reference in New Issue
Block a user