diff --git a/bin/.bin/download-odir b/bin/.bin/download-odir new file mode 100755 index 00000000..e282ece2 --- /dev/null +++ b/bin/.bin/download-odir @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +directory="" +dryrun="false" + + +function multigrep(){ + # will grep for each argument passed + + if [ -n "$1" ]; then + local i="$1" + shift + cat - | grep "$i" | multigrep "$@" + else + cat - + fi +} + +function main(){ + if [ "$dryrun" == "true" ]; then + curl "$directory" | hq a attr href | multigrep "$@" + else + curl "$directory" | hq a attr href | multigrep "$@" | awk "{print \"$directory\" \$1}" | aria2c -i - + fi +} + +if [ -n "$1" ]; then + while [ -n "$1" ]; do + case "$1" in + "-d"|"--dry-run") + dryrun="true" + shift + ;; + *) + directory="$1" + shift + main "$@" + exit 0 + ;; + esac + done + +else + echo "No url passed" +fi + +shift +curl "$directory" | hq a attr href | multigrep "$@"