Skip to content

Commit 9dac7d3

Browse files
authored
feat(contrib): add fuzzel img script (sentriz#144)
* feat(contrib): add fuzzel img script * feat(contrib): hide id `--with-nth` [bug](https://codeberg.org/dnkl/fuzzel/issues/551) [fixed](https://codeberg.org/dnkl/fuzzel/pulls/552) * docs(contrib): fuzzel-img add command
1 parent 27ac1b1 commit 9dac7d3

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

contrib/cliphist-fuzzel-img

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# requires imagemagick to generate thumbnails
4+
5+
thumbnail_size=64
6+
thumbnail_dir="${XDG_CACHE_HOME:-$HOME/.cache}/cliphist/thumbnails"
7+
8+
cliphist_list=$(cliphist list)
9+
if [ -z "$cliphist_list" ]; then
10+
fuzzel -d --placeholder "cliphist: please store something first" --lines 0
11+
rm -rf "$thumbnail_dir"
12+
exit
13+
fi
14+
15+
[ -d "$thumbnail_dir" ] || mkdir -p "$thumbnail_dir"
16+
17+
# Write square shaped thumbnail to cache if it doesn't exist
18+
read -r -d '' thumbnail <<EOF
19+
/^[0-9]+\s<meta http-equiv=/ { next }
20+
match(\$0, /^([0-9]+)\s(\[\[\s)?binary.*(jpg|jpeg|png|bmp)/, grp) {
21+
cliphist_item_id=grp[1]
22+
ext=grp[3]
23+
thumbnail_file=cliphist_item_id"."ext
24+
system("[ -f ${thumbnail_dir}/"thumbnail_file" ] || echo " cliphist_item_id "\\\\\t | cliphist decode | magick - -thumbnail ${thumbnail_size}^ -gravity center -extent ${thumbnail_size} ${thumbnail_dir}/"thumbnail_file)
25+
print \$0"\0icon\x1f${thumbnail_dir}/"thumbnail_file
26+
next
27+
}
28+
1
29+
EOF
30+
31+
item=$(echo "$cliphist_list" | gawk "$thumbnail" | fuzzel -d --placeholder "Search clipboard..." --counter --no-sort --with-nth 2)
32+
exit_code=$?
33+
34+
# ALT+0 to clear history
35+
if [ "$exit_code" -eq 19 ]; then
36+
confirmation=$(echo -e "No\nYes" | fuzzel -d --placeholder "Delete history?" --lines 2)
37+
[ "$confirmation" == "Yes" ] && rm ~/.cache/cliphist/db && rm -rf "$thumbnail_dir"
38+
else
39+
[ -z "$item" ] || echo "$item" | cliphist decode | wl-copy
40+
fi
41+
42+
# Delete cached thumbnails that are no longer in cliphist db
43+
find "$thumbnail_dir" -type f | while IFS= read -r thumbnail_file; do
44+
cliphist_item_id=$(basename "${thumbnail_file%.*}")
45+
if [ -z "$(grep <<< "$cliphist_list" "^${cliphist_item_id}\s\[\[ binary data")" ]; then
46+
rm "$thumbnail_file"
47+
fi
48+
done

readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ Or else query manually:
7777

7878
</details>
7979

80+
<details>
81+
<summary>fuzzel (dmenu mode with images)</summary>
82+
83+
`./cliphist-fuzzel-img`
84+
85+
(Requires [contrib/cliphist-fuzzel-img](./contrib/cliphist-fuzzel-img))
86+
87+
</details>
88+
8089
<details>
8190
<summary>rofi (custom mode)</summary>
8291

0 commit comments

Comments
 (0)