Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions packages/opencode/src/cli/cmd/tui/util/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { lazy } from "../../../../util/lazy.js"
import { tmpdir } from "os"
import path from "path"

export const escapePowerShellValue = (text: string) => text.replace(/`/g, "``").replace(/"/g, '""')

export namespace Clipboard {
export interface Content {
data: string
Expand Down Expand Up @@ -110,8 +112,7 @@ 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, "``")
const escaped = escapePowerShellValue(text)
await $`powershell -NonInteractive -NoProfile -Command "Set-Clipboard -Value \"${escaped}\""`.nothrow().quiet()
}
}
Expand Down
10 changes: 10 additions & 0 deletions packages/opencode/test/clipboard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, expect, it } from "bun:test"
import { escapePowerShellValue } from "../src/cli/cmd/tui/util/clipboard"

describe("escapePowerShellValue", () => {
it("escapes backticks and double quotes for PowerShell", () => {
const input = 'back`tick"quote'
const escaped = escapePowerShellValue(input)
expect(escaped).toBe('back``tick""quote')
})
})