Skip to content

Commit e4e056e

Browse files
committed
feat(Clipboard.ps1): add new Copy-ToClipboard function to handle text copying to clipboard
1 parent f0b7f8c commit e4e056e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Core/Functions/Clipboard.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Function to copy text to the clipboard
2+
function Copy-ToClipboard {
3+
param (
4+
[Parameter(ValueFromPipeline=$true)]
5+
[string]$text
6+
)
7+
8+
begin {
9+
$sb = [System.Text.StringBuilder]::new()
10+
}
11+
12+
process {
13+
$sb.AppendLine($text) | Out-Null
14+
}
15+
16+
end {
17+
if ($PSVersionTable.PSVersion.Major -lt 5) {
18+
Write-Error "Your version of PowerShell does not support Set-Clipboard."
19+
return
20+
}
21+
22+
Set-Clipboard -Value $sb.ToString()
23+
Write-Host "The content has been copied to the clipboard."
24+
}
25+
}

0 commit comments

Comments
 (0)