Skip to content

Commit e81bb86

Browse files
authored
fix: Windows evaluating text on copy (#9293)
1 parent b4d4a1e commit e81bb86

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

packages/opencode/src/cli/cmd/tui/util/clipboard.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,25 @@ export namespace Clipboard {
125125
if (os === "win32") {
126126
console.log("clipboard: using powershell")
127127
return async (text: string) => {
128-
// need to escape backticks because powershell uses them as escape code
129-
const escaped = text.replace(/"/g, '""').replace(/`/g, "``")
130-
await $`powershell -NonInteractive -NoProfile -Command "Set-Clipboard -Value \"${escaped}\""`.nothrow().quiet()
128+
// Pipe via stdin to avoid PowerShell string interpolation ($env:FOO, $(), etc.)
129+
const proc = Bun.spawn(
130+
[
131+
"powershell.exe",
132+
"-NonInteractive",
133+
"-NoProfile",
134+
"-Command",
135+
"[Console]::InputEncoding = [System.Text.Encoding]::UTF8; Set-Clipboard -Value ([Console]::In.ReadToEnd())",
136+
],
137+
{
138+
stdin: "pipe",
139+
stdout: "ignore",
140+
stderr: "ignore",
141+
},
142+
)
143+
144+
proc.stdin.write(text)
145+
proc.stdin.end()
146+
await proc.exited.catch(() => {})
131147
}
132148
}
133149

0 commit comments

Comments
 (0)