Skip to content

Commit 9170bce

Browse files
jshigetomiJustin Chung
authored andcommitted
Add Sqlite option for PSReadline
1 parent 554035e commit 9170bce

File tree

9 files changed

+475
-36
lines changed

9 files changed

+475
-36
lines changed

PSReadLine/Cmdlets.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ public enum AddToHistoryOption
6262
{
6363
SkipAdding,
6464
MemoryOnly,
65-
MemoryAndFile
65+
MemoryAndFile,
66+
SQLite
67+
}
68+
69+
public enum HistoryType
70+
{
71+
Text,
72+
SQLite
6673
}
6774

6875
public enum PredictionSource
@@ -107,6 +114,12 @@ public class PSConsoleReadLineOptions
107114

108115
public const string DefaultContinuationPrompt = ">> ";
109116

117+
/// <summary>
118+
/// The default history format is text. The SQLite is experimental.
119+
/// It is not recommended to use it for production yet.
120+
/// </summary>
121+
public const HistoryType DefaultHistoryType = HistoryType.Text;
122+
110123
/// <summary>
111124
/// The maximum number of commands to store in the history.
112125
/// </summary>
@@ -198,6 +211,7 @@ public PSConsoleReadLineOptions(string hostName, bool usingLegacyConsole)
198211
ResetColors();
199212
EditMode = DefaultEditMode;
200213
ScreenReaderModeEnabled = Accessibility.IsScreenReaderActive();
214+
HistoryType = DefaultHistoryType;
201215
ContinuationPrompt = DefaultContinuationPrompt;
202216
ContinuationPromptColor = Console.ForegroundColor;
203217
ExtraPromptLineCount = DefaultExtraPromptLineCount;
@@ -232,6 +246,13 @@ public PSConsoleReadLineOptions(string hostName, bool usingLegacyConsole)
232246
"PowerShell",
233247
"PSReadLine",
234248
historyFileName);
249+
SqliteHistorySavePath = System.IO.Path.Combine(
250+
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
251+
"Microsoft",
252+
"Windows",
253+
"PowerShell",
254+
"PSReadLine",
255+
hostName + "_history.db");
235256
}
236257
else
237258
{
@@ -333,6 +354,7 @@ public object ContinuationPromptColor
333354
/// that do invoke the script block - this covers the most useful cases.
334355
/// </summary>
335356
public HashSet<string> CommandsToValidateScriptBlockArguments { get; set; }
357+
public HistoryType HistoryType { get; set; } = HistoryType.Text;
336358

337359
/// <summary>
338360
/// When true, duplicates will not be recalled from history more than once.
@@ -372,6 +394,11 @@ public object ContinuationPromptColor
372394
/// The path to the saved history.
373395
/// </summary>
374396
public string HistorySavePath { get; set; }
397+
398+
/// <summary>
399+
/// The path to the SQLite history database.
400+
/// </summary>
401+
public string SqliteHistorySavePath { get; set; }
375402
public HistorySaveStyle HistorySaveStyle { get; set; }
376403

377404
/// <summary>
@@ -655,6 +682,20 @@ public EditMode EditMode
655682
[AllowEmptyString]
656683
public string ContinuationPrompt { get; set; }
657684

685+
[Parameter]
686+
public HistoryType HistoryType
687+
{
688+
get => _historyType.GetValueOrDefault();
689+
set
690+
{
691+
_historyType = value;
692+
_historyTypeSpecified = true;
693+
}
694+
}
695+
696+
public HistoryType? _historyType = HistoryType.Text;
697+
internal bool _historyTypeSpecified;
698+
658699
[Parameter]
659700
public SwitchParameter HistoryNoDuplicates
660701
{

0 commit comments

Comments
 (0)