Save clipboard images to a timestamped file and return a ready-to-paste path for OpenCode (Linux-first, X11/Wayland aware).
Automate the common flow where pasting an image into terminal chat does not work: extract image data from the clipboard, save it to a file, and provide a path the user can reference in OpenCode.
~/Pictures/opencode/clip-YYYYMMDD-HHMMSS.<ext>.@/home/user/Pictures/opencode/clip-....png).X11 or Wayland) when relevant:echo "${XDG_SESSION_TYPE:-unknown}"
xclip.wl-paste (package wl-clipboard).If missing, provide the installation command for the detected distro, then continue.
Save clipboard image into a stable directory:
mkdir -p "$HOME/Pictures/opencode"
xclip)mkdir -p "$HOME/Pictures/opencode"
mime="$(xclip -selection clipboard -t TARGETS -o | tr ' ' '\n' | grep '^image/' | head -n1)"
if [ -z "$mime" ]; then
echo "Clipboard does not currently contain an image. Copy an image first, then retry." >&2
exit 1
fi
case "$mime" in
image/png) ext="png" ;;
image/jpeg) ext="jpg" ;;
image/webp) ext="webp" ;;
image/gif) ext="gif" ;;
*) mime="image/png"; ext="png" ;;
esac
f="$HOME/Pictures/opencode/clip-$(date +%Y%m%d-%H%M%S).$ext"
xclip -selection clipboard -t "$mime" -o > "$f" && printf '%s\n' "$f"
wl-paste)mkdir -p "$HOME/Pictures/opencode"
mime="$(wl-paste --list-types | grep '^image/' | head -n1)"
if [ -z "$mime" ]; then
echo "Clipboard does not currently contain an image. Copy an image first, then retry." >&2
exit 1
fi
case "$mime" in
image/png) ext="png" ;;
image/jpeg) ext="jpg" ;;
image/webp) ext="webp" ;;
image/gif) ext="gif" ;;
*) mime="image/png"; ext="png" ;;
esac
f="$HOME/Pictures/opencode/clip-$(date +%Y%m%d-%H%M%S).$ext"
wl-paste --type "$mime" > "$f" && printf '%s\n' "$f"
sudo apt update && sudo apt install -y xclipsudo apt update && sudo apt install -y wl-clipboardsudo pacman -S xclip or sudo pacman -S wl-clipboardsudo dnf install -y xclip or sudo dnf install -y wl-clipboardAfter saving successfully, respond with:
<absolute_path>@<absolute_path>If the clipboard has no image MIME type, respond with: