52 lines
1.4 KiB
Bash
Executable file
52 lines
1.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
||
|
||
thumb_dir="${XDG_CACHE_HOME:-$HOME/.cache}/clipvault/thumbs"
|
||
mkdir -p "$thumb_dir"
|
||
|
||
clip_list="$(clipvault list)"
|
||
|
||
# nettoyer les vignettes orphelines
|
||
for thumb in "$thumb_dir"/*; do
|
||
[ -e "$thumb" ] || continue
|
||
clip_id="${thumb##*/}"
|
||
clip_id="${clip_id%.*}"
|
||
check=$(printf '%s\n' "$clip_list" | rg "^${clip_id}\s")
|
||
if [ -z "$check" ]; then
|
||
rm -f "$thumb"
|
||
fi
|
||
done
|
||
|
||
# programme gawk : détecter les entrées image, générer les thumbs, préfixer par img:
|
||
read -r -d '' prog <<EOF
|
||
match(\$0, /^([0-9]+)\s\[\[ binary data .*image\/(jpeg|jpg|png|bmp|webp)/, grp) {
|
||
id = grp[1]
|
||
ext = grp[2]
|
||
image = id "." ext
|
||
cmd = "[ -f $thumb_dir/" image " ] || printf \"" id "\\n\" | clipvault get | magick - -resize '256x256>' $thumb_dir/" image
|
||
system(cmd)
|
||
print "img:$thumb_dir/" image
|
||
next
|
||
}
|
||
1
|
||
EOF
|
||
|
||
choice=$(
|
||
gawk <<< "$clip_list" "$prog" |
|
||
wofi -I --dmenu --cache-file=/dev/null \
|
||
-Dimage_size=100 -Dynamic_lines=true \
|
||
--xoffset=600 --yoffset=20 --width=45% --height=45% --gtk-dark
|
||
)
|
||
|
||
[ -z "$choice" ] && exit 1
|
||
|
||
if [ "${choice:0:4}" = "img:" ]; then
|
||
thumb_file="${choice:4}"
|
||
clip_id="${thumb_file##*/}"
|
||
clip_id="${clip_id%.*}"
|
||
else
|
||
# on prend l’ID (premier champ) de la ligne choisie
|
||
clip_id="$(printf '%s\n' "$choice" | awk '{print $1}')"
|
||
fi
|
||
|
||
# récupérer l’entrée choisie et la remettre dans le clipboard
|
||
printf '%s\n' "$clip_id" | clipvault get | wl-copy
|