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
11 changes: 11 additions & 0 deletions packages/core/src/v1/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ export const Info = Schema.Struct({
description: "Additional instruction files or patterns to include",
}),
layout: Schema.optional(ConfigLayoutV1.Layout).annotate({ description: "@deprecated Always uses stretch layout." }),
clipboard: Schema.optional(
Schema.Struct({
linux: Schema.optional(
Schema.Struct({
enablePrimaryCopy: Schema.optional(Schema.Boolean).annotate({
description: "Copy to primary clipboard in addition to regular clipboard on Linux (Wayland/X11)",
}),
}),
),
}),
).annotate({ description: "Clipboard configuration" }),
permission: Schema.optional(ConfigPermissionV1.Info),
tools: Schema.optional(Schema.Record(Schema.String, Schema.Boolean)),
attachment: Schema.optional(ConfigAttachmentV1.Info).annotate({
Expand Down
6 changes: 6 additions & 0 deletions packages/opencode/src/cli/cmd/tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,14 @@ export const TuiThreadCommand = cmd({

try {
const { Effect } = await import("effect")
const { Config } = await import("@/config/config")
const { AppRuntime } = await import("@/effect/app-runtime")
const { run } = await import("../tui/layer")
const { createLegacyTuiPluginHost } = await import("@/plugin/tui/runtime")
const clipboardConfig = await AppRuntime.runPromise(Config.Service.use((cfg) => cfg.get())).catch(() => ({}))
if (clipboardConfig.clipboard?.linux?.enablePrimaryCopy) {
process.env.OPENCODE_CLIPBOARD_PRIMARY_COPY = "true"
}
await Effect.runPromise(
run({
url: transport.url,
Expand Down
19 changes: 16 additions & 3 deletions packages/tui/src/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ export function copyCommand(
os: NodeJS.Platform,
wayland: boolean,
has: (name: string) => boolean,
primary?: boolean,
): string[] | undefined {
if (os === "darwin" && has("osascript")) return ["osascript"]
if (os === "linux" && wayland && has("wl-copy")) return ["wl-copy"]
if (os === "linux" && has("xclip")) return ["xclip", "-selection", "clipboard"]
if (os === "linux" && has("xsel")) return ["xsel", "--clipboard", "--input"]
if (os === "linux" && wayland && has("wl-copy")) return primary ? ["wl-copy", "--primary"] : ["wl-copy"]
if (os === "linux" && has("xclip"))
return primary ? ["xclip", "-selection", "primary"] : ["xclip", "-selection", "clipboard"]
if (os === "linux" && has("xsel"))
return primary ? ["xsel", "--primary", "--input"] : ["xsel", "--clipboard", "--input"]
if (os === "win32" && has("powershell.exe")) {
return [
"powershell.exe",
Expand Down Expand Up @@ -117,8 +120,18 @@ function getCopyMethod() {
})())
}

async function writePrimary(text: string) {
const { which } = await import("@opencode-ai/core/util/which")
const native = copyCommand(platform(), Boolean(process.env.WAYLAND_DISPLAY), (name) => Boolean(which(name)), true)
if (!native) return
await command(native[0], native.slice(1), text).catch(() => undefined)
}

export async function write(text: string) {
writeOsc52(text)
const method = await getCopyMethod()
await method(text)
if (process.env.OPENCODE_CLIPBOARD_PRIMARY_COPY === "true") {
await writePrimary(text)
}
}
Loading