summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLuke Parker <[email protected]>2026-01-19 09:27:30 +1000
committerGitHub <[email protected]>2026-01-18 17:27:30 -0600
commite81bb86795c062dae736568c9c4a4426e8fe9474 (patch)
treef2f1a5b1d7d1308177ce4340a6644a83472b6eec
parentb4d4a1ea7d2e590e3963b36580989404377e4ce4 (diff)
downloadopencode-e81bb86795c062dae736568c9c4a4426e8fe9474.tar.gz
opencode-e81bb86795c062dae736568c9c4a4426e8fe9474.zip
fix: Windows evaluating text on copy (#9293)
-rw-r--r--packages/opencode/src/cli/cmd/tui/util/clipboard.ts22
1 files changed, 19 insertions, 3 deletions
diff --git a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts
index 2526f4171..0e287fbc4 100644
--- a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts
+++ b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts
@@ -125,9 +125,25 @@ export namespace Clipboard {
if (os === "win32") {
console.log("clipboard: using powershell")
return async (text: string) => {
- // need to escape backticks because powershell uses them as escape code
- const escaped = text.replace(/"/g, '""').replace(/`/g, "``")
- await $`powershell -NonInteractive -NoProfile -Command "Set-Clipboard -Value \"${escaped}\""`.nothrow().quiet()
+ // Pipe via stdin to avoid PowerShell string interpolation ($env:FOO, $(), etc.)
+ const proc = Bun.spawn(
+ [
+ "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(() => {})
}
}