forked from sayan01/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg
executable file
·30 lines (27 loc) · 1.05 KB
/
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
29
30
#!/bin/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
tmp1="$(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" > "$tmp1"
rm "${df}" -rf
mkdir -p "${df}"
while IFS="" read -r line || [ -n "$line" ]; do
timeout 2s wget -P "${df}" -T 1 --quiet "${line}" &
done < <(cat "${tmp1}")
rm "$tmp1"
echo "Waiting for downloads to finish"
while echo "$(jobs)" | grep -q "Running" ; do echo > /dev/null ; done
echo "Opening images for selection"
images="$(sxiv "${df}" -otr)"
if [[ -z "$images" ]]; then exit ; fi
echo "$images" | while read image; do
xclip -selection clipboard -t image/png -i "$image" && notify-send "Image copied"
done