fix: Windows evaluating text on copy (#9293)
This commit is contained in:
@@ -125,9 +125,25 @@ export namespace Clipboard {
|
|||||||
if (os === "win32") {
|
if (os === "win32") {
|
||||||
console.log("clipboard: using powershell")
|
console.log("clipboard: using powershell")
|
||||||
return async (text: string) => {
|
return async (text: string) => {
|
||||||
// need to escape backticks because powershell uses them as escape code
|
// Pipe via stdin to avoid PowerShell string interpolation ($env:FOO, $(), etc.)
|
||||||
const escaped = text.replace(/"/g, '""').replace(/`/g, "``")
|
const proc = Bun.spawn(
|
||||||
await $`powershell -NonInteractive -NoProfile -Command "Set-Clipboard -Value \"${escaped}\""`.nothrow().quiet()
|
[
|
||||||
|
"powershell.exe",
|
||||||
|
"-NonInteractive",
|
||||||
|
"-NoProfile",
|
||||||
|
"-Command",
|
||||||
|
"[Console]::InputEncoding = [System.Text.Encoding]::UTF8; Set-Clipboard -Value ([Console]::In.ReadToEnd())",
|
||||||
|
],
|
||||||
|
{
|
||||||
|
stdin: "pipe",
|
||||||
|
stdout: "ignore",
|
||||||
|
stderr: "ignore",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
proc.stdin.write(text)
|
||||||
|
proc.stdin.end()
|
||||||
|
await proc.exited.catch(() => {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user