61 lines
2.0 KiB
Bash
Executable File
61 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
export WAYLAND_DISPLAY=wayland-0
|
|
export XDG_RUNTIME_DIR=/run/user/$(id -u)
|
|
|
|
thumb_dir="${XDG_CACHE_HOME:-$HOME/.cache}/cliphist/thumbs"
|
|
mkdir -p "$thumb_dir"
|
|
|
|
make_thumb() { # $1 - исходник, $2 - результат
|
|
if command -v gdk-pixbuf-thumbnailer >/dev/null 2>&1; then
|
|
gdk-pixbuf-thumbnailer -s 256 "$1" "$2" 2>/dev/null
|
|
elif command -v magick >/dev/null 2>&1; then
|
|
magick "$1" -resize '256x256>' "$2" 2>/dev/null
|
|
elif command -v convert >/dev/null 2>&1; then
|
|
convert "$1" -resize '256x256>' "$2" 2>/dev/null
|
|
fi
|
|
# если тулза нет/ошибка — отдаём оригинал, wofi сам смасштабирует
|
|
[ -s "$2" ] || cp -f "$1" "$2"
|
|
}
|
|
|
|
wofi_input=""
|
|
|
|
while read -r line; do
|
|
[[ "$line" == *"<meta http-equiv="* ]] && continue
|
|
[[ -z "$line" ]] && continue
|
|
|
|
id="${line%%[[:space:]]*}"
|
|
|
|
if [[ "$line" == *binary* ]]; then
|
|
thumb_path="${thumb_dir}/${id}.png"
|
|
|
|
if [ ! -s "$thumb_path" ]; then
|
|
tmp="$(mktemp)"
|
|
# ВАЖНО: передаём строку через pipe,
|
|
# иначе decode прочитает stdin цикла и «съест» список
|
|
printf '%s\n' "$line" | cliphist decode > "$tmp" 2>/dev/null
|
|
[ -s "$tmp" ] && make_thumb "$tmp" "$thumb_path"
|
|
rm -f "$tmp"
|
|
fi
|
|
|
|
if [ -s "$thumb_path" ]; then
|
|
wofi_input+="img:${thumb_path}\n"
|
|
else
|
|
wofi_input+="${line}\n"
|
|
fi
|
|
else
|
|
wofi_input+="${line}\n"
|
|
fi
|
|
done <<< "$(cliphist list)"
|
|
|
|
choice="$(printf '%b' "$wofi_input" | wofi -I --dmenu --cache-file=/dev/null \
|
|
-Dimage_size=100 -Dynamic_lines=true --prompt "Буфер обмена")"
|
|
|
|
[ -z "$choice" ] && exit 0
|
|
|
|
if [[ "$choice" == img:* ]]; then
|
|
f="${choice#img:}"
|
|
id="$(basename "$f" .png)"
|
|
printf '%s\t' "$id" | cliphist decode | wl-copy
|
|
else
|
|
printf '%s\n' "$choice" | cliphist decode | wl-copy
|
|
fi |