MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / readClipboardFilePathLinux

Function readClipboardFilePathLinux

cli/src/utils/clipboard-image.ts:483–518  ·  view source on GitHub ↗

* Read file path from clipboard when a file has been copied (Linux). * Returns the file path if found, null otherwise.

()

Source from the content-addressed store, hash-verified

481 * Returns the file path if found, null otherwise.
482 */
483function readClipboardFilePathLinux(): string | null {
484 try {
485 // Try to get file URI from clipboard
486 let result = spawnSync('xclip', [
487 '-selection', 'clipboard',
488 '-t', 'text/uri-list',
489 '-o',
490 ], { encoding: 'utf-8', timeout: 1000 })
491
492 if (result.status !== 0) {
493 // Try wl-paste for Wayland
494 result = spawnSync('wl-paste', ['--type', 'text/uri-list'], {
495 encoding: 'utf-8',
496 timeout: 1000,
497 })
498 }
499
500 if (result.status === 0 && result.stdout) {
501 const output = result.stdout.trim()
502 // Parse file:// URLs
503 const lines = output.split('\n')
504 for (const line of lines) {
505 const trimmed = line.trim()
506 if (trimmed.startsWith('file://')) {
507 const filePath = decodeURIComponent(trimmed.slice(7))
508 if (existsSync(filePath)) {
509 return filePath
510 }
511 }
512 }
513 }
514 return null
515 } catch {
516 return null
517 }
518}
519
520/**
521 * Read file path from clipboard when a file has been copied.

Callers 1

readClipboardFilePathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected