#!/bin/sh

previewdir="$HOME/.ncmpcpp/cover"
if [ -n "$previewdir/FIFO_UEBERZUG" ]; then
	printf '{"action": "remove", "identifier": "PREVIEW"}\n' > "$previewdir/FIFO_UEBERZUG"
fi

nextImage="$(find $previewdir -type f -iname '*jpg')"

if [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
    printf '{"action": "add", "identifier": "PREVIEW", "x": "%s", "y":"%s", "width": "%s", "height": "%s", "scaler": "contain", "path": "%s"}\n' 1 0 49 49 "${nextImage}" > "$previewdir/FIFO_UEBERZUG"
    exit 1
else
    chafa "${nextImage}" 
fi
