Skip to content
Open
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: 9 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,7 @@ import path from "path"
import fs from "fs/promises"
import * as Filesystem from "../../../../util/filesystem"
import * as Process from "../../../../util/process"
import { sniffAttachmentMime } from "../../../../util/media"

// Lazy load which and clipboardy to avoid expensive execa/which/isexe chain at startup
const getWhich = lazy(async () => {
Expand Down Expand Up @@ -93,13 +94,19 @@ export async function read(): Promise<Content | undefined> {
if (os === "linux") {
const wayland = await Process.run(["wl-paste", "-t", "image/png"], { nothrow: true })
if (wayland.stdout.byteLength > 0) {
return { data: Buffer.from(wayland.stdout).toString("base64"), mime: "image/png" }
const mime = sniffAttachmentMime(new Uint8Array(wayland.stdout), "text/plain")
if (mime === "image/png") {
return { data: Buffer.from(wayland.stdout).toString("base64"), mime: "image/png" }
}
}
const x11 = await Process.run(["xclip", "-selection", "clipboard", "-t", "image/png", "-o"], {
nothrow: true,
})
if (x11.stdout.byteLength > 0) {
return { data: Buffer.from(x11.stdout).toString("base64"), mime: "image/png" }
const mime = sniffAttachmentMime(new Uint8Array(x11.stdout), "text/plain")
if (mime === "image/png") {
return { data: Buffer.from(x11.stdout).toString("base64"), mime: "image/png" }
}
}
}

Expand Down
Loading