Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public class SetClipboardCommand : PSCmdlet
[Parameter]
public SwitchParameter PassThru { get; set; }

/// <summary>
/// Gets or sets whether to use OSC52 escape sequence to set the clipboard of host instead of target.
/// </summary>
[Parameter]
[Alias("ToLocalhost")]
public SwitchParameter AsOSC52 { get; set; }

/// <summary>
/// This method implements the BeginProcessing method for Set-Clipboard command.
/// </summary>
Expand Down Expand Up @@ -129,8 +136,28 @@ private void SetClipboardContent(List<string> contentList, bool append)

if (ShouldProcess(setClipboardShouldProcessTarget, "Set-Clipboard"))
{
Clipboard.SetText(content.ToString());
SetClipboardContent(content.ToString());
}
}

/// <summary>
/// Set the clipboard content.
/// </summary>
/// <param name="content">The content to store into the clipboard.</param>
private void SetClipboardContent(string content)
{
if (!AsOSC52)
{
Clipboard.SetText(content);
return;
}

var bytes = System.Text.Encoding.UTF8.GetBytes(content);
var encoded = System.Convert.ToBase64String(bytes);
var osc = $"\u001B]52;;{encoded}\u0007";

var message = new HostInformationMessage { Message = osc, NoNewLine = true };
WriteInformation(message, new string[] { "PSHOST" });
}
}
}