Skip to content

Add Sqlite option for PSReadline #4833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PSReadLine.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ task LayoutModule BuildPolyfiller, BuildMainModule, {
Copy-Item "Polyfill/bin/$Configuration/netstandard2.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/netstd" -Force
Copy-Item "Polyfill/bin/$Configuration/net6.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/net6plus" -Force

$binPath = "PSReadLine/bin/$Configuration/netstandard2.0/publish"
$binPath = "PSReadLine/bin/$Configuration/netstandard2.0/win-x64/publish"
Copy-Item $binPath/Microsoft.PowerShell.PSReadLine.dll $targetDir
Copy-Item $binPath/Microsoft.PowerShell.Pager.dll $targetDir

Expand Down
43 changes: 42 additions & 1 deletion PSReadLine/Cmdlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ public enum AddToHistoryOption
{
SkipAdding,
MemoryOnly,
MemoryAndFile
MemoryAndFile,
SQLite
}

public enum HistoryType
{
Text,
SQLite
}

public enum PredictionSource
Expand Down Expand Up @@ -106,6 +113,12 @@ public class PSConsoleReadLineOptions

public const string DefaultContinuationPrompt = ">> ";

/// <summary>
/// The default history format is text. The SQLite is experimental.
/// It is not recommended to use it for production yet.
/// </summary>
public const HistoryType DefaultHistoryType = HistoryType.Text;

/// <summary>
/// The maximum number of commands to store in the history.
/// </summary>
Expand Down Expand Up @@ -201,6 +214,7 @@ public PSConsoleReadLineOptions(string hostName, bool usingLegacyConsole)
{
ResetColors();
EditMode = DefaultEditMode;
HistoryType = DefaultHistoryType;
ContinuationPrompt = DefaultContinuationPrompt;
ContinuationPromptColor = Console.ForegroundColor;
ExtraPromptLineCount = DefaultExtraPromptLineCount;
Expand Down Expand Up @@ -235,6 +249,13 @@ public PSConsoleReadLineOptions(string hostName, bool usingLegacyConsole)
"PowerShell",
"PSReadLine",
historyFileName);
SqliteHistorySavePath = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"Microsoft",
"Windows",
"PowerShell",
"PSReadLine",
hostName + "_history.db");
}
else
{
Expand Down Expand Up @@ -336,6 +357,7 @@ public object ContinuationPromptColor
/// that do invoke the script block - this covers the most useful cases.
/// </summary>
public HashSet<string> CommandsToValidateScriptBlockArguments { get; set; }
public HistoryType HistoryType { get; set; } = HistoryType.Text;

/// <summary>
/// When true, duplicates will not be recalled from history more than once.
Expand Down Expand Up @@ -375,6 +397,11 @@ public object ContinuationPromptColor
/// The path to the saved history.
/// </summary>
public string HistorySavePath { get; set; }

/// <summary>
/// The path to the SQLite history database.
/// </summary>
public string SqliteHistorySavePath { get; set; }
public HistorySaveStyle HistorySaveStyle { get; set; }

/// <summary>
Expand Down Expand Up @@ -656,6 +683,20 @@ public EditMode EditMode
[AllowEmptyString]
public string ContinuationPrompt { get; set; }

[Parameter]
public HistoryType HistoryType
{
get => _historyType.GetValueOrDefault();
set
{
_historyType = value;
_historyTypeSpecified = true;
}
}

public HistoryType? _historyType = HistoryType.Text;
internal bool _historyTypeSpecified;

[Parameter]
public SwitchParameter HistoryNoDuplicates
{
Expand Down
Loading