Skip to content

Commit

Permalink
Remove MinimumHistoryCommandLength
Browse files Browse the repository at this point in the history
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 }
  • Loading branch information
lzybkr committed Sep 13, 2013
1 parent 1c75b8e commit c5351dd
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 58 deletions.
8 changes: 0 additions & 8 deletions PSReadLine/Cmdlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,6 @@ public SwitchParameter HistorySearchCursorMovesToEnd
}
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
{
Expand Down
29 changes: 1 addition & 28 deletions PSReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,6 @@ static KeyHandler MakeKeyHandler(Action<ConsoleKeyInfo?, object> action, string
/// </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>
Expand Down Expand Up @@ -335,11 +328,7 @@ void ProcessOneKey(ConsoleKeyInfo key, Dictionary<ConsoleKeyInfo, KeyHandler> di

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.
Expand Down Expand Up @@ -458,7 +447,6 @@ private PSConsoleReadLine()
_continuationPromptForegroundColor = DefaultContinuationPromptForegroundColor;
_continuationPromptBackgroundColor = DefaultContinuationPromptBackgroundColor;

_minimumHistoryCommandLength = DefaultMinimumHistoryCommandLength;
_addToHistoryHandler = null;
_historyNoDuplicates = DefaultHistoryNoDuplicates;
_maximumHistoryCount = DefaultMaximumHistoryCount;
Expand Down Expand Up @@ -1791,21 +1779,6 @@ private void SetOptionsInternal(SetPSReadlineOption options)
{
_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;
Expand Down
22 changes: 0 additions & 22 deletions UnitTestPSReadLine/UnitTestReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ private void TestSetup(KeyMode keyMode, params KeyHandler[] keyHandlers)
{
AddToHistoryHandler = null,
HistoryNoDuplicates = PSConsoleReadLine.DefaultHistoryNoDuplicates,
MinimumHistoryCommandLength = PSConsoleReadLine.DefaultMinimumHistoryCommandLength,
MaximumHistoryCount = PSConsoleReadLine.DefaultMaximumHistoryCount,
MaximumKillRingCount = PSConsoleReadLine.DefaultMaximumKillRingCount,
ResetTokenColors = true,
Expand Down Expand Up @@ -886,26 +885,6 @@ public void TestHistoryDuplicates()
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()
{
Expand Down Expand Up @@ -1419,7 +1398,6 @@ public void TestUselessStuffForBetterCoverage()
+ options.HistorySearchCursorMovesToEnd.GetHashCode()
+ options.MaximumHistoryCount.GetHashCode()
+ options.MaximumKillRingCount.GetHashCode()
+ options.MinimumHistoryCommandLength.GetHashCode()
+ options.DingDuration.GetHashCode()
+ options.DingTone.GetHashCode()
+ options.BellStyle.GetHashCode()
Expand Down

0 comments on commit c5351dd

Please sign in to comment.