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
1 change: 1 addition & 0 deletions packages/opencode/src/cli/cmd/tui/config/tui-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ export const TuiInfo = Schema.Struct({
scroll_acceleration: Schema.optional(ScrollAcceleration),
diff_style: Schema.optional(DiffStyle),
mouse: Schema.optional(Schema.Boolean).annotate({ description: "Enable or disable mouse capture (default: true)" }),
linux_clipboard_selection: Schema.optional(Schema.Literals(["clipboard", "primary", "both"])).annotate({ description: "Linux clipboard selection: 'clipboard' (Ctrl+C), 'primary' (middle-click), or 'both' (default: 'both')" }),
})
43 changes: 40 additions & 3 deletions packages/opencode/src/cli/cmd/tui/util/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ChildProcess } from "effect/unstable/process"
import { AppProcess } from "@opencode-ai/core/process"
import * as Filesystem from "../../../../util/filesystem"
import * as Process from "../../../../util/process"
import { get } from "../config/tui"

const writeWithStdin = (cmd: string[], text: string): Promise<void> =>
Effect.runPromise(
Expand Down Expand Up @@ -135,16 +136,52 @@ const getCopyMethod = lazy(async () => {
}

if (os === "linux") {
const config = await get()
const selection = config.linux_clipboard_selection ?? "both"

if (process.env["WAYLAND_DISPLAY"] && which("wl-copy")) {
console.log("clipboard: using wl-copy")
console.log(`clipboard: using wl-copy (${selection})`)
if (selection === "primary") {
return (text: string) => writeWithStdin(["wl-copy", "-p"], text)
}
if (selection === "both") {
return async (text: string) => {
await Promise.allSettled([
writeWithStdin(["wl-copy", "-p"], text),
writeWithStdin(["wl-copy"], text),
])
}
}
return (text: string) => writeWithStdin(["wl-copy"], text)
}
if (which("xclip")) {
console.log("clipboard: using xclip")
console.log(`clipboard: using xclip (${selection})`)
if (selection === "primary") {
return (text: string) => writeWithStdin(["xclip", "-selection", "primary"], text)
}
if (selection === "both") {
return async (text: string) => {
await Promise.allSettled([
writeWithStdin(["xclip", "-selection", "primary"], text),
writeWithStdin(["xclip", "-selection", "clipboard"], text),
])
}
}
return (text: string) => writeWithStdin(["xclip", "-selection", "clipboard"], text)
}
if (which("xsel")) {
console.log("clipboard: using xsel")
console.log(`clipboard: using xsel (${selection})`)
if (selection === "primary") {
return (text: string) => writeWithStdin(["xsel", "--primary", "--input"], text)
}
if (selection === "both") {
return async (text: string) => {
await Promise.allSettled([
writeWithStdin(["xsel", "--primary", "--input"], text),
writeWithStdin(["xsel", "--clipboard", "--input"], text),
])
}
}
return (text: string) => writeWithStdin(["xsel", "--clipboard", "--input"], text)
}
}
Expand Down
Loading