-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contrib: add wofi image script (#85)
* add contrib script for wofi images * add deletion of thumbnails not in history * remove incorrect old comment
- Loading branch information
1 parent
e771265
commit cc3f405
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/bash | ||
|
||
# executes same behaviour as below but with support for images | ||
# | ||
# cliphist list | wofi --dmenu | cliphist decode | ||
# | ||
# produces thumbnails and stores them in XDG_CACHE_HOME | ||
# note: does NOT put in clipboard, call wl-copy yourself! | ||
|
||
# set up thumbnail directory | ||
thumb_dir="${XDG_CACHE_HOME:-$HOME/.cache}/cliphist/thumbs" | ||
mkdir -p "$thumb_dir" | ||
|
||
cliphist_list="$(cliphist list)" | ||
|
||
# delete thumbnails in cache but not in cliphist | ||
for thumb in "$thumb_dir"/*; do | ||
clip_id="${thumb##*/}" | ||
clip_id="${clip_id%.*}" | ||
check=$(rg <<< "$cliphist_list" "^$clip_id\s") | ||
if [ -z "$check" ]; then | ||
>&2 rm -v "$thumb" | ||
fi | ||
done | ||
|
||
# remove unnecessary image tags | ||
# create thumbnail if image not processed already | ||
# print escape sequence | ||
read -r -d '' prog <<EOF | ||
/^[0-9]+\s<meta http-equiv=/ { next } | ||
match(\$0, /^([0-9]+)\s(\[\[\s)?binary.*(jpg|jpeg|png|bmp)/, grp) { | ||
image = grp[1]"."grp[3] | ||
system("[ -f $thumb_dir/"image" ] || echo " grp[1] "\\\\\t | cliphist decode | convert - -resize '256x256>' $thumb_dir/"image ) | ||
print "img:$thumb_dir/"image | ||
next | ||
} | ||
1 | ||
EOF | ||
|
||
choice=$(gawk <<< $cliphist_list "$prog" | wofi -I --dmenu) | ||
|
||
# stop execution if nothing selected in wofi menu | ||
[ -z "$choice" ] && exit 1 | ||
|
||
if [ "${choice::4}" = "img:" ]; then | ||
thumb_file="${choice:4}" | ||
clip_id="${thumb_file##*/}" | ||
clip_id="${clip_id%.*}\t" | ||
else | ||
clip_id="${choice}" | ||
fi | ||
|
||
printf "$clip_id" | cliphist decode |