MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getClipboardCommands

Function getClipboardCommands

src/utils/imagePaste.ts:31–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29// Threshold in characters for when to consider text a "large paste"
30export const PASTE_THRESHOLD = 800
31function getClipboardCommands() {
32 const platform = process.platform as SupportedPlatform
33
34 // Platform-specific temporary file paths
35 // Use CLAUDE_CODE_TMPDIR if set, otherwise fall back to platform defaults
36 const baseTmpDir =
37 process.env.CLAUDE_CODE_TMPDIR ||
38 (platform === 'win32' ? process.env.TEMP || 'C:\\Temp' : '/tmp')
39 const screenshotFilename = 'claude_cli_latest_screenshot.png'
40 const tempPaths: Record<SupportedPlatform, string> = {
41 darwin: join(baseTmpDir, screenshotFilename),
42 linux: join(baseTmpDir, screenshotFilename),
43 win32: join(baseTmpDir, screenshotFilename),
44 }
45
46 const screenshotPath = tempPaths[platform] || tempPaths.linux
47
48 // Platform-specific clipboard commands
49 const commands: Record<
50 SupportedPlatform,
51 {
52 checkImage: string
53 saveImage: string
54 getPath: string
55 deleteFile: string
56 }
57 > = {
58 darwin: {
59 checkImage: `osascript -e 'the clipboard as «class PNGf»'`,
60 saveImage: `osascript -e 'set png_data to (the clipboard as «class PNGf»)' -e 'set fp to open for access POSIX file "${screenshotPath}" with write permission' -e 'write png_data to fp' -e 'close access fp'`,
61 getPath: `osascript -e 'get POSIX path of (the clipboard as «class furl»)'`,
62 deleteFile: `rm -f "${screenshotPath}"`,
63 },
64 linux: {
65 checkImage:
66 'xclip -selection clipboard -t TARGETS -o 2>/dev/null | grep -E "image/(png|jpeg|jpg|gif|webp|bmp)" || wl-paste -l 2>/dev/null | grep -E "image/(png|jpeg|jpg|gif|webp|bmp)"',
67 saveImage: `xclip -selection clipboard -t image/png -o > "${screenshotPath}" 2>/dev/null || wl-paste --type image/png > "${screenshotPath}" 2>/dev/null || xclip -selection clipboard -t image/bmp -o > "${screenshotPath}" 2>/dev/null || wl-paste --type image/bmp > "${screenshotPath}"`,
68 getPath:
69 'xclip -selection clipboard -t text/plain -o 2>/dev/null || wl-paste 2>/dev/null',
70 deleteFile: `rm -f "${screenshotPath}"`,
71 },
72 win32: {
73 checkImage:
74 'powershell -NoProfile -Command "(Get-Clipboard -Format Image) -ne $null"',
75 saveImage: `powershell -NoProfile -Command "$img = Get-Clipboard -Format Image; if ($img) { $img.Save('${screenshotPath.replace(/\\/g, '\\\\')}', [System.Drawing.Imaging.ImageFormat]::Png) }"`,
76 getPath: 'powershell -NoProfile -Command "Get-Clipboard"',
77 deleteFile: `del /f "${screenshotPath}"`,
78 },
79 }
80
81 return {
82 commands: commands[platform] || commands.linux,
83 screenshotPath,
84 }
85}
86
87export type ImageWithDimensions = {
88 base64: string

Callers 2

getImageFromClipboardFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected