-
Notifications
You must be signed in to change notification settings - Fork 20
/
img
executable file
·28 lines (26 loc) · 997 Bytes
/
img
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
apikeypath="$HOME/.config/img.apikey"
if [[ -r "$apikeypath" ]]; then
apikey="$(cat "$apikeypath")"
else
echo "$apikeypath is not present. store your serpapi.com search API Key there"
exit 1
fi
tmp="$(mktemp /tmp/imgXXX)"
df="/tmp/img-google"
query="$(echo "" | rofi -dmenu -p "Enter Query: " )"
echo "Getting link list of images"
curl -G "https://serpapi.com/search.json" --data-urlencode "engine=google" --data-urlencode "q=${query}" --data-urlencode "tbm=isch" --data-urlencode "api_key=${apikey}" | jq -r ".images_results[].original" > "$tmp"
rm "${df}" -rf
mkdir -p "${df}"
while IFS="" read -r line || [ -n "$line" ]; do
timeout 10s wget -P "${df}" --quiet "${line}" &
done < "$tmp"
echo "Waiting for downloads to finish"
wait
echo "Opening images for selection"
images="$(sxiv "${df}" -otr)"
if [[ -z "$images" ]]; then exit ; fi
echo "$images" | while read -r image; do
xclip -selection clipboard -t image/png -i "$image" && notify-send "Image copied"
done