Created
November 1, 2020 12:04
-
-
Save cassava/d658f591c4b6ba25bf7e974834becb63 to your computer and use it in GitHub Desktop.
Bash script to download URLs from the clipboard.
This file contains hidden or 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
#!/bin/bash | |
# Create a pipe for async communication | |
pipe=$(mktemp -u) | |
trap "rm -f $pipe" EXIT | |
if [[ ! -p $pipe ]]; then | |
mkfifo $pipe | |
fi | |
download_loop() { | |
while true; do | |
cat $pipe | while read line; do | |
download_file $line | |
done | |
done | |
echo "Exiting download loop." | |
} | |
download_file() { | |
local url="$1" | |
shift | |
local name="$@" | |
printf "Downloading: % -64s " "$name" | |
wget -q "$url" -O "$name" | |
printf "done.\n" | |
} | |
main() { | |
download_loop & | |
while clipnotify; do | |
link=$(xsel -p 2>/dev/null) | |
text=$(zenity --entry) | |
if [[ "$text" == "" ]]; then | |
continue | |
fi | |
echo "$link" "$text" >> $pipe & | |
done | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment